加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax与后台通信 -- Response.End()

发布时间:2020-12-16 02:12:38 所属栏目:百科 来源:网络整理
导读:前台代码: 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

前台代码:

<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中的结果将是整个页面。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读