JQuery升级和AJAX
我刚从1.4升级到jQuery1.5.2,我的PostForm现在不工作了。它确实会发布到页面,但即使没有错误,它也会说有错误JQuery升级和AJAX,ajax,post,jquery,Ajax,Post,Jquery,我刚从1.4升级到jQuery1.5.2,我的PostForm现在不工作了。它确实会发布到页面,但即使没有错误,它也会说有错误 function TestPostForm(){ $.ajax({ type: "POST", url: "process.jsp", data: 'operation=Test&ui=TestUser',
function TestPostForm(){
$.ajax({
type: "POST",
url: "process.jsp",
data: 'operation=Test&ui=TestUser',
dataType: "application/x-www-form-urlencoded",
async: false,
success: function(response) {
alert('Success');
return response;
},
error: function(xhr, ajaxOptions, thrownError) {
alert("There was an error : " + xhr.status);
}
});
}
Java代码:process.jsp
if (operation.equals("Test")) {
String ui = request.getParameter("ui");
out.println("Ok" + ui);
}
使用Firebug嗅探AJAX活动,并查看服务器上生成的错误。这可能会给您一个线索。您的问题在于
数据类型
,您应该定义的是contentTypeString
:
contentType: "application/x-www-form-urlencoded"
dataType
定义您希望脚本返回的数据类型(xml、json、脚本或html),而contentType
传递您在请求中发送的内容类型
您可以在jQuery API上阅读关于这些选项的更多信息:为什么不以这种方式发送数据
data:{'operation':'Test','ui':'TestUser'}
Yo不需要显式地指定dataType
。out变量是什么。它是否会得到回显?