Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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:
JavaScript
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.
Posted
v3
Comments
Irbaz Haider Hashmi 11-Feb-13 10:14am    
When a control is render on page the id of the html elements get changed. More information will be required in order to understand this. What error you are getting? or your javascript function is not executed at all.

Try by adding debugger; in javascript.
Try moving your code on the page rather than writing it on control.
rkuttarakabat 11-Feb-13 10:32am    
The java script is executed, but its not able to call the web service, i am getting an alert as error as mentioned in the code. I have to write the code in user control as i want to use this usercontrol in many a places.
Irbaz Haider Hashmi 11-Feb-13 10:50am    
try entering the complete URL of the webservice. what error are you getting? 403,404?
rkuttarakabat 11-Feb-13 10:58am    
its not at all calling the the web service, if possible can u give me an example for it.
rkuttarakabat 12-Feb-13 4:32am    
i am getting an error as "object XMLHttpRequest"

1 solution

 
Share this answer
 
Comments
rkuttarakabat 12-Feb-13 1:39am    
this is working in normal pages, but i want in a usercontrol, and its not helping me to call the webservice.
José Amílcar Casimiro 12-Feb-13 5:38am    
Check this: http://stackoverflow.com/questions/579024/calling-an-ascx-page-method-using-jquery

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900