Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 无法使用json asp.net从web服务获取数据_Jquery_Asp.net_Json_Web Services - Fatal编程技术网

Jquery 无法使用json asp.net从web服务获取数据

Jquery 无法使用json asp.net从web服务获取数据,jquery,asp.net,json,web-services,Jquery,Asp.net,Json,Web Services,我的项目中有一个web服务,并使用jquery从另一个页面调用它。 但并没有从web服务获取数据,我已经在web服务中使用断点检查了它并没有从jquery调用中被命中。我的密码是 网络服务 namespace DOC_HTML { /// <summary> /// Summary description for JsonService /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebS

我的项目中有一个web服务,并使用jquery从另一个页面调用它。 但并没有从web服务获取数据,我已经在web服务中使用断点检查了它并没有从jquery调用中被命中。我的密码是

网络服务

namespace DOC_HTML
{
/// <summary>
/// Summary description for JsonService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class JsonService : System.Web.Services.WebService
{

    [WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
    public static string DocTypeList()
    {
        MastersService MS = new MastersService();   
        DataSet ds = new DataSet();
        ds.ReadXml(new XmlNodeReader(MS.DocumentTypeList()));

        List<dropDown> listDocType = new List<dropDown>();

        if (ds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dropDown objst = new dropDown();
                objst.Id = Convert.ToString(ds.Tables[0].Rows[i]["docCode"]);
                objst.Name = Convert.ToString(ds.Tables[0].Rows[i]["docName"]);
                listDocType.Insert(i, objst);
            }

        }
        JavaScriptSerializer jscript = new JavaScriptSerializer();
        return jscript.Serialize(listDocType);
    }

}

public class dropDown
{
    public string Id { get; set; }
    public string Name { get; set; }
}
}
网页代码

<script type="text/javascript">     

    $(document).ready(function () {
        loadData();
    });

    function loadData() {  
            $.ajax({
                type: "POST",
                url: "../JsonService.asmx/DocTypeList",
                data: {},
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    var jsdata = JSON.parse(data.d);
                    $.each(jsdata, function (key, value) {
                        $('#<%= ddlDocType.ClientID %>').append($("<option></option>").val(value.Id).html(value.Name));
                });
            },
            error: function (e) {
                alert(JSON.stringify(e));
            }
        });          
    }

</script>

看看这个问题。我怀疑您的JQuery ajax调用正在寻找一个可以接受POST的方法,但可能没有。

线索在响应中:未知的web方法DocTypeList。您是否调试了找不到该方法的原因?由于您没有向web服务传递任何数据,请删除该行contentType:application/json;字符集=utf-8。有时这也会导致问题。我试着不工作。@Rorymcrossan如何调试它。得到解决方案我刚从web方法中删除了静态,它工作了。。。。