ajax與後台通訊 -- Response.End()

來源:互聯網
上載者:User

標籤:ajax   response.end   後台   

前台代碼:

<span style="font-size:14px;">var json = {    width: w,    height: h,    category: canvas_category,    name: canvas_json_name,    description: canvas_description,    border: canvas_border,    lineWidth: defaultLineW,    json: canvas_json};</span>

 

<span style="font-size:14px;">$.ajax({ url: "Canvas_panel.aspx", data: json,    success: function (result)    {        if (result == "Exist")        {            alert("There is a same record in DB, you can't save it.");        }        else if (result == "Success")        {            alert('Save Success.');        }    },    error: function (err)    {        alert(err);    }});</span>

參數可以寫成json格式,放到data中傳輸,也可以加到url中用queryString方式傳輸。

後台代碼:

<span style="font-size:14px;">if (Request["name"] != null){int width = int.Parse(Request["width"].ToString());int height = int.Parse(Request["height"].ToString());string name = Request["name"].ToString();string json = Request["json"].ToString();string sql = "select * from warehouse_model where code='" + name + "' and json='" + strJson + "'";DataTable dtValidate = _dataAccess.GetTables(sql);if (dtValidate.Rows.Count > 0){Response.Write("Exist");Response.End();}else{Response.Write("Success");Response.End();}}</span>

注意這裡面的Reponse.End()方法,它的含義是強迫Web伺服器停止執行更多的指令碼,並發送當前結果,檔案中剩餘的內容將不被處理。如果不加上這個方法,前台Result中的結果將是整個頁面。

ajax與後台通訊 -- Response.End()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.