Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Calling an ASMX Web Service through JQuery .Ajax

Calling an ASMX Web Service through JQuery .Ajax

Scheduled Pinned Locked Moved JavaScript
javascripthelpquestionhtmlcom
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dbrenth
    wrote on last edited by
    #1

    The following is my HTML page. My problem is with invokeService(). It correctly determines the body and places it in data - but then it never sends the data. Fiddler shows no JSON data was sent. The Success routine is called but the data is null (as would be expected with no input data). Can anyone tell me what I am missing or did wrong. How do I send the JSON to the service? Thanks Brent

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <title>Test Voter Info</title>
    <script type="text/javascript" src="jquery-1.4.1.js"></script>

    <script type="text/javascript">
    
        function invokeService() {
            var value = document.getElementById("voter").value;
            var loc = "https://www.voterfocus.com/mais/asmx/service1.asmx";
            var body = "{'FVRSVoterIDNumber':'" + value + "', 'County':'lee', 'CKey':'------'}";
            input.innerText = body;
            $.ajax({
                type: "POST",
                url: loc + "/GetFVRSVoter",
                data: body,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: ajaxSucceeded,
                error: ajaxFailed
            });
    
        }
    
        function ajaxFailed(data) {
            result.innerText = data.status + ' ' + data.statusText;
        }
    
        function ajaxSucceeded(data) {
            if (data != null)
                result.innerText = data.d;
            else
                result.innerText = data;
        }
    </script>
    

    </head>
    <body>

        One Voter: <input type="text" id="voter" />
        <input type="button" onclick="invokeService();" value="GO" />
    
    
    Input Body:
    
    
    Raw Result:
    

    </body>
    </html>

    Brent

    Z 1 Reply Last reply
    0
    • D dbrenth

      The following is my HTML page. My problem is with invokeService(). It correctly determines the body and places it in data - but then it never sends the data. Fiddler shows no JSON data was sent. The Success routine is called but the data is null (as would be expected with no input data). Can anyone tell me what I am missing or did wrong. How do I send the JSON to the service? Thanks Brent

      <html xmlns="http://www.w3.org/1999/xhtml">

      <head>
      <title>Test Voter Info</title>
      <script type="text/javascript" src="jquery-1.4.1.js"></script>

      <script type="text/javascript">
      
          function invokeService() {
              var value = document.getElementById("voter").value;
              var loc = "https://www.voterfocus.com/mais/asmx/service1.asmx";
              var body = "{'FVRSVoterIDNumber':'" + value + "', 'County':'lee', 'CKey':'------'}";
              input.innerText = body;
              $.ajax({
                  type: "POST",
                  url: loc + "/GetFVRSVoter",
                  data: body,
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: ajaxSucceeded,
                  error: ajaxFailed
              });
      
          }
      
          function ajaxFailed(data) {
              result.innerText = data.status + ' ' + data.statusText;
          }
      
          function ajaxSucceeded(data) {
              if (data != null)
                  result.innerText = data.d;
              else
                  result.innerText = data;
          }
      </script>
      

      </head>
      <body>

          One Voter: <input type="text" id="voter" />
          <input type="button" onclick="invokeService();" value="GO" />
      
      
      Input Body:
      
      
      Raw Result:
      

      </body>
      </html>

      Brent

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      If it hits the success function that tells me it called your service correctly. Did you put a breakpoint in your webmethod?

      There are only 10 types of people in the world, those who understand binary and those who don't.

      D 1 Reply Last reply
      0
      • Z ZurdoDev

        If it hits the success function that tells me it called your service correctly. Did you put a breakpoint in your webmethod?

        There are only 10 types of people in the world, those who understand binary and those who don't.

        D Offline
        D Offline
        dbrenth
        wrote on last edited by
        #3

        The service is not mine, unfortunately, but, like I said, Fiddler confirms that no data was sent. Is there something I need to do to prepare the data to be sent?

        Brent

        Z 1 Reply Last reply
        0
        • D dbrenth

          The service is not mine, unfortunately, but, like I said, Fiddler confirms that no data was sent. Is there something I need to do to prepare the data to be sent?

          Brent

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #4

          What is the signature for your GetFVRSVoter() method?

          There are only 10 types of people in the world, those who understand binary and those who don't.

          D 1 Reply Last reply
          0
          • Z ZurdoDev

            What is the signature for your GetFVRSVoter() method?

            There are only 10 types of people in the world, those who understand binary and those who don't.

            D Offline
            D Offline
            dbrenth
            wrote on last edited by
            #5

            I'm wondering if I'm wasting my time here. History: Our vendor created this service and also gave us a web site where everything works, but he never gave us access to the WSDL. My employer wanted it to do something different, so asked me to extract the functionality and use it in our own web site. So I don't even have a signature, I am just copying out what is in the vendor's JavaScript file. Is doing something like that even possible? Or am I running in to cross-site scripting problems? This could be something entirely different. But when I run the same script in the vendor's web page, Fiddler shows the data being sent and so when mine gets called and no data is sent, I am just hoping it is me doing something wrong instead of me trying to do something impossible. Thanks

            Brent

            Z Richard DeemingR 2 Replies Last reply
            0
            • D dbrenth

              I'm wondering if I'm wasting my time here. History: Our vendor created this service and also gave us a web site where everything works, but he never gave us access to the WSDL. My employer wanted it to do something different, so asked me to extract the functionality and use it in our own web site. So I don't even have a signature, I am just copying out what is in the vendor's JavaScript file. Is doing something like that even possible? Or am I running in to cross-site scripting problems? This could be something entirely different. But when I run the same script in the vendor's web page, Fiddler shows the data being sent and so when mine gets called and no data is sent, I am just hoping it is me doing something wrong instead of me trying to do something impossible. Thanks

              Brent

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #6

              Thanks for the additional info. It is possible you are having cross-site issues; however, I believe the error function is called when that happens.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              D 1 Reply Last reply
              0
              • Z ZurdoDev

                Thanks for the additional info. It is possible you are having cross-site issues; however, I believe the error function is called when that happens.

                There are only 10 types of people in the world, those who understand binary and those who don't.

                D Offline
                D Offline
                dbrenth
                wrote on last edited by
                #7

                It may be a proxy authentication problem. I managed to get it working in c#, but had to use proxy authentication. How would I do proxy authentication for this in javascript?

                Brent

                Z 1 Reply Last reply
                0
                • D dbrenth

                  It may be a proxy authentication problem. I managed to get it working in c#, but had to use proxy authentication. How would I do proxy authentication for this in javascript?

                  Brent

                  Z Offline
                  Z Offline
                  ZurdoDev
                  wrote on last edited by
                  #8

                  dbrenth wrote:

                  How would I do proxy authentication for this in javascript?

                  Not sure. I haven't had to do that in JS but here's the documentation for .ajax, http://api.jquery.com/jquery.ajax/[^]. If it can be done it would be using one of those properties, perhaps the headers.

                  There are only 10 types of people in the world, those who understand binary and those who don't.

                  1 Reply Last reply
                  0
                  • D dbrenth

                    I'm wondering if I'm wasting my time here. History: Our vendor created this service and also gave us a web site where everything works, but he never gave us access to the WSDL. My employer wanted it to do something different, so asked me to extract the functionality and use it in our own web site. So I don't even have a signature, I am just copying out what is in the vendor's JavaScript file. Is doing something like that even possible? Or am I running in to cross-site scripting problems? This could be something entirely different. But when I run the same script in the vendor's web page, Fiddler shows the data being sent and so when mine gets called and no data is sent, I am just hoping it is me doing something wrong instead of me trying to do something impossible. Thanks

                    Brent

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #9

                    dbrenth wrote:

                    Or am I running in to cross-site scripting problems?

                    That's the most likely issue - cross-domain AJAX requests won't work without making changes to the server you're calling. You would either need to change the service to use JSONP[^], or set the Access-Control-Allow-Origin header[^] on the server to allow calls from your site. If you don't have access to the server that's hosting the service, there's nothing you can do from the client side. You'd need to write your own service to proxy calls to the remote service for your site. The client-side code would call your service; your service would then call the original service, and return the results to the client.


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups