将C#实体类传递给json-jquery时,HTTPGET失败 [英] HTTPGET fail when passing C# entity class to json-jquery

查看:107
本文介绍了将C#实体类传递给json-jquery时,HTTPGET失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的jquery:

$.ajax({
        type: 'GET',
        url: '/services/Service.asmx/FamilyHistory',
        data: JSON.stringify({
            userID: 10,
            historyID: famid
        }),
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(val) {
            var famHist = val.d;
            alert(famHist.ID);
        },
        error: function() {
            parent.$.jGrowl('<b>Failed</b>',
                 {
                     header: 'User Action:',
                     life: 3000
                 });
        }
    });

我的班级:

public sealed class FamilyHistoryEntity
{
    public string ID { get; set; }
    public string RelativeName { get; set; }
}

我的Web服务:

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
    public FamilyHistoryEntity FamilyHistory(int userID, string historyID)
    {
         return GetFamilyHistory(historyID, userID); // returns a FamilyHistoryEntity class
    }

问题是,我什至无法使其成为Web服务的断点,它只会引发jquery ajax事件错误.

Problem is, i can't even make it do a breakpoint onto the webservice, it just throws the jquery ajax event of error.

推荐答案

为什么要使用stringify函数?似乎正在寻找使用字符串参数而不是方法具有的两个参数的方法.

Why are you using the stringify function? It would seem like it is looking to call a method with a string parameter rather than the two parameters you have for your method.

也许我错过了什么?

因此,您将data属性更改为:

So you would change the data property to:

data: { userID: 10, historyID: famid },

特别是因为您将contentType指定为json.

Especially since you specify the contentType as json.

这篇关于将C#实体类传递给json-jquery时,HTTPGET失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆