這是我的PHP頁面(在不同的URL)...JSONP請求PHP頁面無法正常工作(跨域)
<?php
header('Content-Type: application/json');
?>
stat({"online":1});
,這是我的jQuery:
$(document).ready(function(){
var url = 'http://blah.com/jsontest.php?callback=stat';
$.getJSON(url, function(data) {
if (data.online !== undefined) {
console.log('yay');
}
}).error(function() {
console.log('no');
});
});
對於一些因爲它總是記錄「否」,即它運行錯誤功能。
使用jQuery 1.5.2的任何想法?
如果你console.log(數據)你會得到什麼? – 2011-05-05 11:37:22
您的'getJSON'調用是否被識別爲JSONP? – 2011-05-05 11:38:47
@Nicola - 什麼都沒有,因爲錯誤函數被稱爲不是成功函數。 – Quentin 2011-05-05 11:41:37