3 回答

TA貢獻1802條經驗 獲得超6個贊
dataType:"json",
您需要刪除這一行,因為您沒有從 process-request.php 返回 json,它只是返回 html 代碼。

TA貢獻1839條經驗 獲得超15個贊
問題可能出在您的 AJAX 調用上。您指定:
contentType:"application/json; charset-utf-8",
dataType:"json",
您正在從 PHP 頁面發回 HTML。試試那個。/echo/html/ 和其他編輯適用于 JSFiddle。只需放回舊值,更改數據類型并取出內容類型。
$("#cc").on("change",function(){
var selected = $(this).val();
$.ajax({
type:"POST",
url:"process-request.php",
data: { cc : selected },
dataType:"html",
async:false,
success: ccSuccess,
error: AjaxFailed
});
});
function ccSuccess(result)
{ alert(result);
$("#response").html(result);
}
function AjaxFailed(result)
{
$("#response").html("<p class='error'>Failed to Load State/Province Codes</p>");
}

TA貢獻1796條經驗 獲得超10個贊
試試這個。
return json_encode($countryArr[$country])在你的 php 腳本中做一個。刪除回聲部分。
function ccSuccess(result)
{
alert(result);
var country = JSON.parse(result);
var html = "";
html += "<select name='sp'>";
for(var i =0; i < country.length; i++)
{
html +="<option value='"+ country[i] +"'>"+ country[i] +"</option>";
}
html += "</select>";
$("#response").html(html);
}
- 3 回答
- 0 關注
- 202 瀏覽
添加回答
舉報