getJSON 不执行回调函数的问题
js:
function check(domain)
{
var otitle = null;
var title = null;
otitle = $("#txtchatquestion");
title = otitle.val();
title=title.replace(/[ ]/g,"");
if(title=="")
{
alert('请输入问题内容!');
return ;
}
var url =
"http://ashx."+domain+"/ChatAjax.ashx?time=" + Math.random() + "&callback=?";
$.getJSON(
url,
{"type":"tijiao","tijiao_content":""+title+""},
function(json){
alert(json.msg);
}
);
}
ashx:
string callback = context.Request.QueryString["callback"];
content = context.Request.QueryString["tijiao_content"].ToString();
string sql = string.Empty;
DBOracle ora = new DBOracle();
sql = "insert into web_question(title,content) values('" + content + "','" + content + "')";
int num = ora.ExecSql(sql);
context.Response.ContentType = "text/plain";
if (num > 0)
{
context.Response.Write(callback + "({\"msg\":\"添加成功!\"})");
}
else
{
context.Response.Write(callback + "({\"msg\":\"添加失败!\"})");
}
context.Response.End();
如上代码 总是不执行回调函数 各位大侠 帮忙看看 js报错 缺少' ; ' 分号
补充一下:能将数据传入ashx 并成功插入数据库 就是不能将数据返回js页面 我用getJSON 是因为要跨域!
------解决方案--------------------
context.Response.ContentType = "application/json";
试试