2011-04-18 55 views
0

我剛從1.4升級到JQuery 1.5.2,我的PostForm現在不能工作。它發佈到頁面,但即使沒有錯誤,它說有錯誤。JQuery升級和AJAX

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); 
     } 
+0

什麼是'out' var。它會得到迴應嗎? – Neal 2011-04-18 19:07:44

回答

0

你的問題是與dataType,你應該定義什麼是contentTypeString

contentType: "application/x-www-form-urlencoded" 

dataType定義你希望你的腳本,而contentType傳遞返回(XML,JSON,腳本或HTML)的數據類型您在請求中發送的內容類型。

你可以閱讀更多關於jQuery的API這些選項:http://api.jquery.com/jQuery.ajax/

0

嗅嗅使用Firebug的AJAX活動,看到正在您的服務器上生成了什麼錯誤。這可能會給你一個線索。

1

爲什麼不把數據這樣?

data: {'operation': 'Test', 'ui': 'TestUser'}喲不需要明確指定dataType