Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery升级和AJAX_Ajax_Post_Jquery - Fatal编程技术网

JQuery升级和AJAX

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',

我刚从1.4升级到jQuery1.5.2,我的PostForm现在不工作了。它确实会发布到页面,但即使没有错误,它也会说有错误

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变量是什么。它是否会得到回显?