无法从javascript函数调用asp.net webservice

问题描述:

我创建了一个 usercontrol ,它将接受邮政编码并显示州和城市(以json格式返回)。

所以我在javacript中为zipcode文本框编写了keyup函数。

在javascript方面,我想调用webservice。

这是我在 ascx 页面写的代码:

I have created an "usercontrol" which will accept the zip code and display state and city(returning in json format).
So I have written keyup function for zipcode textbox in javacript.
In javascript side, I want to call the webservice.
Here is my code written in the ascx page:

function OnKeyUP(s, e) {
        var len = txtZip.GetText();
            var newstring = len.replace(/[_-]/g, '');
            if (newstring.length == 5) {              

                $.ajax(
                    {
                        type: "POST",
                        url: '~/CityStateZipCodes.asmx/GetCityStateZipCodes',
                        data: "{'zip':'77853'}",
                        async: false,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                            alert(msg);                           
                        },
                        error: function () {
                            alert('error');
                        }
                    });
                }
             }



但我无法拨打网络服务,有人可以帮我解决如何打电话或举例。


But I am unable to call the webservice, can someone please help me out how to call, or give an example.

.ajax(
{
type: POST
url:' 〜/ CityStateZipCodes.asmx / GetCityStateZipCodes '
数据: {'zip':'77853'}
async: false
contentType: application / json; charset = utf-8
dataType: json
成功: function (msg){
alert(msg);
},
错误: function (){
alert('' 错误');
}
});
}
}
.ajax( { type: "POST", url: '~/CityStateZipCodes.asmx/GetCityStateZipCodes', data: "{'zip':'77853'}", async: false, contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert(msg); }, error: function () { alert('error'); } }); } }



但我无法拨打网络服务,有人可以帮我解决如何打电话或举例。


But I am unable to call the webservice, can someone please help me out how to call, or give an example.


查看本文致电使用JavaScript的HTML页面中的Web服务 [ ^ ]