由于API只有xml,所以ajax请求dataType必须以xml形式发送。我正在使用插件脚本来让我绕过跨域问题。脚本在下面找到。
由于使用了插件,响应以json的形式返回。Jquery AJAX 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);
}
});
'placement.innerHTML = ...'行是无效的 - 不知道你要去那里,但你的逗号分隔值会给出一个javascript错误。 –
我是一个Jquery的新手,我不知道如何才能将这些项目从json响应传递到我的内容div。我也尝试将它们附加到它,但也没有解决。 –
如果您的回复是XML,并且您正在调用'parseJSON',它肯定会炸毁。 –