0
我試圖運行以下AJAX請求,向Codeigniter發送數據和CSRF數據,但Chrome開發人員工具報告有關「意外的令牌」。 我一直無法解決這個問題,但我想「數據」字段導致錯誤。Chrome在運行AJAX請求時報告「Unexpected token」
這是我的AJAX請求調用:
$(document).ready(function(){
$('#country').on('change',function(){
var countryID = $(this).val();
if(countryID){
$.ajax({
type:'POST',
url:'/index.php/campaigns/fetch_departments',
data:{'csrf_token':'4932809e3753b95b81245ff4439a121d','country_id:'+countryID},
success:function(html){
$('#state').html(html);
$('#city').html('<option value="">Select state first</option>');
}
});
}else{
$('#state').html('<option value="">Select country first</option>');
$('#city').html('<option value="">Select state first</option>');
}
});
...
'country_id ='+ countryID'應爲''country_id':countryID' – Andreas
請顯示瀏覽器收到的頁面中顯示的實際生成的Javascript,以便我們可以看到您的PHP爲實際腳本生成了什麼。你可以在瀏覽器中使用View/Source來獲得它。這也將幫助您看到實際生成的腳本的外觀,並使您更有可能發現自己的編碼錯誤。 – jfriend00
@ jfriend00更新 – kanarifugl