2013-04-23 57 views
0

我嘗試通過Ajax發送一個表單到另一個頁面的服務器端,保存並保留在同一頁面中。在服務器asp.net獲取ajax的數據表格

Ajax代碼:在

function SaveJS() { 
    $.ajax({ 
     type: "POST", 
     url: 'http://' + $('#ip').val() + 'EditSochen.aspx?id=3', 
     data: $('#form1').serialize(), 
     success: function() { 
      $('#div2').css("display", "none") 
     } 
    }); 
} 

服務器代碼的 'http://' + $( '#IP')VAL()+ 'EditSochen.aspx ID = 3?' 頁面:

if (Page.IsPostBack) 
     { 
      Response.Clear();   //clears the existing HTML 
      Response.ContentType = "text/plain"; //change content type 
      Response.Write("fgf"); //writes out the new name 
      Response.End();    //end 
     } 

它到達另一個頁面的服務器端,但返回另一個頁面,而不是留在同一頁面,爲什麼?

感謝,

+0

是否有您不使用ASHX文件,該解決方案的一個原因? – Constanta 2013-04-23 13:37:49

回答

0

我發現了問題 - 我需要return falseSaveJS() FUNC。

代碼:

function SaveJS() { 
    $.ajax({ 
     type: "POST", 
     url: 'http://' + $('#ip').val() + 'EditSochen.aspx?id=3', 
     data: $('#form1').serialize(), 
     success: function() { 
      $('#div2').css("display", "none") 
     } 
    }); 
return false; 
}