js,jquery无法获取后台(Response.Write())返回的json
前台:
function Open() { if ($("#FileUpload").val() != "") { $.get('VerAdd.aspx?operate=Open&filePath=' + $("#FileUpload").val(), function (info) { //info.XXX }, 'json'); } else { alert("请选择文件呀,亲!"); } }
后台:
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["operate"] != null) { Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); switch (Request.QueryString["operate"]) { case "Open": Open(Request.QueryString["filePath"]); break; } Response.End(); } } private void Open(string filePath) { string json = "{\'HEXLE\':\'0\',\'BINLE\':\'83512\',\'FIRVER\':\'0100\',\'HARVER\':\'23F0\',\'CRC32\':\'23 F0 12 5C \',\'CRC16\':\'B3 FA \',\'FILELE\':\'83512\',\'BLOCKSUM\':\'82\'}"; Response.Write(json); }
最后才发现,json不能为单引号。遂把\' 修改为 \",好了。自己做个笔记。