【问题标题】:getting"SyntaxError: JSON.parse: unexpected character" error while make ajax call from user control page in asp.net从 asp.net 中的用户控制页面进行 ajax 调用时出现“SyntaxError:JSON.parse:意外字符”错误
【发布时间】:2012-02-24 18:43:51
【问题描述】:

我第一次使用来自 asax 页面的 ajax 调用。

它工作正常我在 C# 页面中获取数据,但是当尝试获取成功函数时,我在错误函数中得到错误消息

“SyntaxError: JSON.parse: 意外字符”

这是我的代码

var options = {
         type: "POST",
         url: "ChemistrieAddToCart.aspx",
         data: data,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         async: false,
         success: function () {                 
             alert("sucsess");
         },
         error: function (xhr, status, error) {
             alert("failed" + xhr.responseText);
             alert(error);
             alert(status);

         }
     };
     var returntext = $.ajax(options).responseText;
     if (returntext = "added") {
         alert("Matched");
        window.location="shoppingcart.aspx"
     }
     else {
         alert("not completed");
        }

谢谢。

【问题讨论】:

  • 什么是数据?显示字符串
  • 1-800-optisource.com/Email/image/jsonstring.jpg" width="497" height="394"/>

标签: c# asp.net json jquery


【解决方案1】:

如果您将 <img src="1-800-optisource.com/Email/image/jsonstring.jpg"; width="497" height="394"/> 作为 Json 字符串传递,它是错误的,您可能会先查看 json 格式,然后传递值可能会给您想法并解决您的问题

在这里检查 json:http://www.json.org/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2017-01-24
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    相关资源
    最近更新 更多