<script>
$(document).ready(function() {
$.ajax({url: "http://somedomain/app/district.php", success: function(result){
$("#district").html(result);
}});
$.ajax({url: "http://somedomain/app/category.php", success: function(result){
$("#crop-category").html(result);
}});
$('#district').change(function(){
var value=$('#district').val();
$('#upazila').parent().find('span').html("<span> </span>");
$.ajax({
url: "http://somedomain/app/upazila.php",
type: "get", //send it through get method
data:{value},
success: function(response) {
$("#upazila").html(response);
},
error: function(xhr) {
//Do Something to handle error
}
});
});
});
</script>
这是我的jquery代码,我构建了一个应用程序。对于前 2 个 ajax 请求,我得到了值,但是当我通过 get 请求传递一些变量时,代码不起作用。在调试的心情中,它说未捕获的语法错误:意外的令牌 } 索引.html:36这是
数据:{值},
但它在浏览器上运行良好...请帮忙。
问题是在你的第三个ajax
调用中,data
字段不是有效的对象,data
应该是对象、字符串或数组。 传递value
如下所示:
data: value
您无需在花括号内提及它。或者,如果它是一个字符串或数组,并且您希望它作为对象传递,则按如下所示进行传递:
data: {value: value}