无法从javascript函数调用asp.net webservice [英] Unable to call asp.net webservice from javascript function

查看:69
本文介绍了无法从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
成功:< span class =code-keyword> 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服务 [ ^ ]


这篇关于无法从javascript函数调用asp.net webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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