我有以下代碼,目前即時在我的本地機器上運行。我正在調用一個名爲getxml.php的php腳本,它應該將xml文件的內容作爲響應。
但是,代替GET請求,在Firebug中,我看到正在進行OPTIONS請求,如 OPTIONS getxml.php。我想即時通訊沒有提出跨域Ajax請求,但仍然面臨着這個問題。有任何解決這個問題的方法嗎 ?
var employee_list = new Object;
$(function(){
$.ajax({
type:"GET",
url:"http://localhost/projectname/getxml.php",
datatype:"xml",
success: function(xml){
$(xml).find('employee').each(function(){
var name_text = $(this).find('name').text();
var url_text = $(this).find('url').text();
employee_list[name_text] = url_text;
$('<li></li>').html(name_text + ' (' + url_text + ')').appendTo('#update-target ol');
});
} //closing function
}); //closing $.ajax
}); //closing $(
getxml.php
<?php
//Send the xml file as response
header('Content-type: text/xml');
readfile('employee_results.xml');
?>
謝謝
其中是PHP中的XML?您只需發送一些標題 – streetparade
感謝您的回覆streetparade。readfile()函數讀取xml文件的內容併發送它。 – samw
實際上沒有這樣的東西作爲HTTP中的OPTIONS請求。即使你設置了'datatype:'OPTIONS'',底層的XHR對象也不會理解這一點。是什麼讓你相信HTTP動詞是「OPTIONS」? – jpsimons