Javascript 我的jQuery.ajax()解析器出错的原因是什么?

Javascript 我的jQuery.ajax()解析器出错的原因是什么?,javascript,.net,ajax,json,web-services,Javascript,.net,Ajax,Json,Web Services,我正试图通过javascript$.Ajax调用从Web服务获取JSON <script type="text/javascript"> $(function () { $("#" + "@Model.BidObjectId").submit(function () { alert("Test"); var param = { 'id': "@Model.BidObjectId" }; $

我正试图通过javascript$.Ajax调用从Web服务获取JSON

<script type="text/javascript">
    $(function () {
        $("#" + "@Model.BidObjectId").submit(function () {
            alert("Test");
            var param = { 'id': "@Model.BidObjectId" };
            $.ajax({
                url: "http://localhost:11523/Service1.svc/GetBidObject",
                dataType: "jsonp",
                contentType: "application/json;charset=utf-8",
                type: "GET",
                data: JSON.stringify(param),
                success: function (msg) {
                    alert("success");
                    if (msg != null) {
                        return msg.URL;
                    }
                },
                error: function (msg2) {
                    alert(msg2);
                }
            });
            return false;
        });
    });
</script>

公共字符串[]GetBidObject(字符串id)
{
BidObject BidObject=new BidObject(){BidObjectId=1,Title=“callback”};
JavaScriptSerializer ser=新的JavaScriptSerializer();
字符串结果=serial.Serialize(bidobject);
List listResult=新列表();
listResult.Add(结果);
返回listResult.ToArray();
}
我不使用ASP.NET,而是使用Razor

[编辑]


如果我在Fiddler中通过json更改jsonp,我可以读取我的调用是
选项http://localhost:11523/Service1.svc/GetBidObject?{%22id%22:%220%22}使用chrome的HTTP/1.1
。小提琴手什么也没发现。ajax调用从未完成。。。我真的不明白。

JSON和查询字符串是两码事。通过GET(或POST)发送数据时不需要使用JSON

jQuery将正确序列化
参数
,并生成URL:

http://localhost:11523/Service1.svc/GetBidObject?id=123&callback=jquery1234

然后您可以从后端的查询字符串中读取
id
值。

@cruzzea in Fiddler?Fiddler中的响应是HTTP/1.1 405方法不允许。当我使用JSONP时,一切似乎都是正确的。在Fiddler中,我可以在JSON选项卡下看到我的JSON。可能是您的服务器出了问题,如果您访问浏览器中的链接,您将得到与ajax调用相同的响应,并且是“cuzzea”,没有目标{%22id%22:%220%22}&=1340728692841 HTTP/1.1,我如何才能取回数据?@DranDane:从哪里取回数据?你在问什么?我不知道“Web服务”是如何工作的,我只是注意到您的
$.ajax
调用是错误的。我的Web服务返回一个字符串列表(JSON),我想用这些新数据更新我的页面。@DranDane:当使用我的答案中的
$.ajax
调用时,您是否仍然收到错误?你得到了什么回应?您可能需要更改webservice以正确读取查询字符串(因为它不再是JSON)
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "/GetBidObject?id={id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        string[] GetBidObject(string id);
        public string[] GetBidObject(string id)
        {
            BidObject bidobject = new BidObject() { BidObjectId = 1, Title = "callback" };

            JavaScriptSerializer ser = new JavaScriptSerializer();
            string result =  ser.Serialize(bidobject);
            List<string> listResult = new List<string>();
            listResult.Add(result);
            return listResult.ToArray(); 
        }
$.ajax({
    url: "http://localhost:11523/Service1.svc/GetBidObject",
    dataType: "jsonp",
    type: "GET",
    data: param,
    success: function (msg) {
        alert("success");
        if (msg != null) {
            return msg.URL;
        }
    },
    error: function (msg2) {
        alert(msg2);
    }
});