2014-10-02 40 views
0

我試圖使用Ajax帖子從一個國家被選中時從xml返回省份列表。ajax - 發佈到網頁,並獲得已經以xml格式返回的內容

這是錯誤消息我得到:

enter image description here

的XML似乎是好了 - 錯誤信息顯示正確的州/省在選擇的國家,但由於某些原因,錯誤和我無法使用成功回調函數。 我相信我應該在我的php中迴應xml響應,並且$(document).ready函數應該包含ajaxError處理函數,但是我無法在成功回調中提醒我的省份/州的列表。有沒有人知道我在這裏錯過了什麼?

HTML

<select name="aff_country" onChange="loadStates(this.value);"> 
    <option value="Select Me">Select Me</option> 
</select> 

的Javascript

$(document).ready(function() { 
    $(document).ajaxError(function(e,xhr,settings,exception) { 
     alert('Error Page: ' + settings.url + '\n\n'+'Error Message:\n' + xhr.responseText); 
    }); 
}); 

function loadStates(country_value) { 
    $.post("/states.php", {con_name: country_value}, function(data) { 
     console.log(data); 
    },"xml"); 
} 

XML(PHP)

<? 
$request_obj = new Request(); 
$request_obj->flds = $_REQUEST; 

$states = array(); 
$states = $country_bus_obj->states($request_obj,$_CONFIG); 

$xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 
$xml .= "<response>"; 
$xml .= "<status>" . $status . "</status>"; 
$xml .= "<message>" . $trans->msg . "</message>"; 
$xml .= "<states>"; 
foreach ($states as $item) { 
    $xml .= "<state>"; 
    $xml .= "<name>" . $item['sta_name'] . "</name>"; 
    $xml .= "</state>"; 
} 
$xml .= "</states>"; 
$xml .= "</response>"; 

header('Content-type: text/xml'); 
header('Cache-Control: no-cache'); 
echo $xml; 
?> 

回答

0

如果有人遇到同樣的問題...我通過刪除我包含的php文件底部的所有換行符來解決此問題。

相關問題