API は xml のみであるため、ajax リクエストの dataType は xml として送信する必要があります。プラグイン スクリプトを使用して、クロス ドメインの問題を回避できるようにしています。スクリプトは以下にあります。
プラグインが使用されているため、レスポンスは json として返されます。
個々の応答データを表示できない理由がわかりません。なんとか表示できたのは、ブラウザの [object object] だけです。
これを機能させるための提案は大歓迎です。
$.ajax({
url: 'http://api.smartpea.com/api/deal/?title=water&zip=90210, ///URL + User Input
dataType: 'xml',
type: 'get',
beforeSend: function(){// Before Send, Add the Loader
$("#loading").show();
},
complete: function(){// Once Request is complete, Remove the Loader
$("#loading").hide();
},
success: function(data){
var placement = document.getElementById('content');// location to where response is to be displayed to the user
jQuery.parseJSON(data); parse the json response
$.each(data, function(i) {
placement.innerHTML = data[i].Title, data[i]. BrandName, data[i]. CurrentPrice, data[i].Category; //adding the response data to the content holder in the browser
});
},
error: function (xhr, ajaxOptions, thrownError){// Error Logger
console.log(xhr, ajaxOptions, thrownError);
}
});