我想在Windows Phone 7.5上使用下面的代碼與jQuery。每次我嘗試爲xml創建ajax請求時,都會從錯誤處理程序中返回「Access is Denied」。 JSONP不會在這種情況下工作,不幸的是,因爲我需要的數據只有XML。我不知道我會如何解決這個問題。Windows Phone 7/IE9 jQuery ajax「訪問被拒絕」
編輯:我應該指出,代碼適用於Chrome和Safari。但是我沒有Windows機器來測試IE。 編輯2:在IE9上測試出現相同的錯誤。
的javascript:
function loadData(index) {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$.ajax({
url: "http://foo.bar/some.xml",
dataType: "xml",
success: parseData,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
};
PHP代理來獲取XML
<?php
header('Content-type: text/xml');
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
$intme = date('YmdHis');
$start = $_GET['ind'];
$url = "http://some.data.source/data.xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
你在用什麼?手機差距,在本地應用程序內製作webapp或webcontrol? – 2012-01-28 21:05:11
只是普通的jQuery的webapp。 – exiva 2012-01-28 22:45:33