首先普利文普拉萨德的所有答案,我觉得正确的。我只想添加一些关于“为什么...?”这个问题将会回答的描述。而不是“如何...?”。
如果你每HTTP GET发送到服务器的参数有一些特殊的字符,那就不会在URL中使用不编码,所以你必须使用至少
url:'AjaxActions/OrderNotesUpdate.aspx?OrderID=' +
encodeURIComponent(OrderID) + '&Notes=' + encodeURIComponent($('#txtNotes').val())
下一步:您可以使用jQuery.param()
相对于的encodeURIComponent
和地点 '&' 字符paramters之间编码URL参数:
$.ajax({
url:'AjaxActions/OrderNotesUpdate.aspx?' +
$.param({OrderID: OrderID, Notes: $('#txtNotes').val()}),
async:false})
或
$.ajax({
url:'AjaxActions/OrderNotesUpdate.aspx' +
data: { OrderID: OrderID, Notes: $('#txtNotes').val()},
async:false})
哪个地方'?' url
和data
之间编码$.param
如果url
不包含'?'否则使用'&'代替。
下一步:只要有可能,您应该尝试使用$.ajax
的异步版本。人们需要查看更多的代码来帮助你。一般来说,它应该是
$.ajax({
url:'AjaxActions/OrderNotesUpdate.aspx' +
data: { OrderID: OrderID, Notes: $('#txtNotes').val()},
success:function(response) {
/* here use can use response.responseText. For examlpe you can
code which call the syncrone $.ajax before and used
the return value here */
}
})
有一个很好的理由使用'async:false',它会在请求期间锁定客户端浏览器。使用同步AJAX的最常见原因是缺乏对如何实现回调的理解。 – Matt 2010-09-25 10:15:18