確定這很奇怪。當我嘗試測試我的代碼時,出現以下錯誤。出於某種原因,我的URL地址顯示爲兩次。獲取JSON數據404(未找到)
GET http://howtodeployit.com/howtodeployit.com/api/get_recent_posts/ 404 (Not Found)
JS:
$(document).on('pagebeforeshow', '#blogposts', function() {
//$.mobile.showPageLoadingMsg();
$.ajax({
url: "http:/howtodeployit.com/api/get_recent_posts/",
dataType: "json",
jsonpCallback: 'successCallback',
async: true,
beforeSend: function() { $.mobile.showPageLoadingMsg(true); },
complete: function() { $.mobile.hidePageLoadingMsg(); },
success:function(data){
console.log(data);
// successful request; do something with the data
$('#postlist').empty();
var html = '';
for (i=0; i<data.posts.length; i++) {
html += '<li>' + data.posts.title + '</li>';
}
$("#postlist").append(html).listview("refresh");
},
error: function (request,error) {
alert('Network error has occurred please try again!');
}
});
});
網址: 「HTTP:/howtodeployit.com/api/get_recent_posts/」 嘗試修復http:// – Gabbar
您是使用'json'還是'jsonp'?爲什麼你在請求中使用域名? – Izkata
我正在基於一個例子。該網址爲我提供了JSON供稿。它是否正確?必須指向json文件的url? – Chelseawillrecover