Ajax and background communication -- Response. End ()
Front-end code:
var json = { width: w, height: h, category: canvas_category, name: canvas_json_name, description: canvas_description, border: canvas_border, lineWidth: defaultLineW, json: canvas_json};
$.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); }});
Parameters can be written in json format, transmitted in data, or added to the url for queryString transmission.
Background code:
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();}}
Note that the Reponse. End () method forces the Web server to stop executing more scripts and send the current results. The remaining content in the file will not be processed. If this method is not added, the Result in the foreground Result will be the whole page.