Calling a WebService method from JQuery within a .NET UserControl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RichRadio
    New Member
    • Feb 2010
    • 1

    Calling a WebService method from JQuery within a .NET UserControl

    Hi,

    I have the following script within a user control

    Code:
    	<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    	<script type="text/javascript">
    
    	    jQuery().ready(function() {
            
    	        $("#btnNext").click(function() {
    
    	            var options = {
    	                type: "POST",
    	                url: "/services/UserServices.asmx/ValidateFields",
    	                data: "{}",
    	                contentType: "application/json; charset=utf-8",
    	                dataType: "json",
    	                success: function(ret) {
    	                    alert(ret);
    	                }
    	            };
    
    	            $.ajax(options);
    	        });
    	    });
               </script>
               <input id="btnNext" type="button" value="Next"  />

    When I add the user control to a test page and click the button, nothing happens.

    If I move this code to the test page itself (default.aspx), clicking the button calls the web method and returns successully.

    So, I conclude that it isn't possible to do this within a user control which seems rather restrictive.... ...or am I missing something?

    Any help....most appreciated!


    Kind Regards


    Richard.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I think it has to do with your URL.
    Try providing an absolute URL to the web service....

    -Frinny

    Comment

    • Shooby
      New Member
      • Sep 2011
      • 1

      #3
      Just in case anyone else stumbles across this looking for the same answer, check out http://stackoverflow.com/questions/5...d-using-jquery It states that this cannot be done as the ascx form does not represent a real URL.

      Comment

      Working...