下面的方法我通过jQuery调用我的pageload函数。
请告诉我如何传递查询字符串。
<script type="text/javascript" src="script/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#Customers').change(function() {
$.ajax({
contentType: "text/html; charset=utf-8",
data: "CustomerID=" + $('#Customers').val(),
url: "FetchCustomer.aspx",
dataType: "html",
success: function(data) {
$("#CustomerDetails").html(data);
}
});
});
});
</script>
我有几个问题
请指导我。谢谢
GET
和POST
与contentType
无关你可以用contentType:"html"
设置type:"POST"
当您设置type:"POST"
时,表单值在查询字符串中不可见,如www.utopia.com?name=john&lastName=smith
The HTML specifications technically define the difference between "GET" and "POST" so that
former means that form data is to be encoded (by a browser) into a URL while the latter means that
the form data is to appear within a message body. But the specifications also give the usage
recommendation that the "GET" method should be used when the form processing is "idempotent", and in
those cases only. As a simplification, we might say that "GET" is basically for just getting
(retrieving) data whereas "POST" may involve anything, like storing or updating data, or ordering a
product, or sending E-mail.
REF:http://www.cs.tut.fi/~jkorpela/forms/methods.html#fund
$(document).ready(function() {
$('#Customers').change(function() {
$.ajax({
type:'POST',
contentType: "text/html; charset=utf-8",
data:{CustomerID:$('#Customers').val()},
url: "FetchCustomer.aspx",
dataType: "html",
success: function(data) {
$("#CustomerDetails").html(data);
}
});
});
});
您只需删除内容类型并指定类型即可
$.ajax({
type:"POST",
data: "CustomerID=" + $('#Customers').val(),
url: "FetchCustomer.aspx",
success: function(data) {
$("#CustomerDetails").html(data);
}
});