SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery Ajax Question

    I'm trying to use this web service http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP

    with jQuery...

    but the below code does not seem to work? Help!


    Code JavaScript:
        $(document).ready(function() {
        // Add the page method call as an onclick handler for the div.
          $("#Result").click(function() {
             $.ajax({
              type: "POST",
              url: "http://www.webservicex.net/uszip.asmx/GetInfoByZIP",
              data: "USZip=80202",
              contentType: "application/x-www-form-urlencoded",
              //dataType: "json",
              success: function(msg) {
                // Replace the div's content with the page method's return.
                $("#Result").text(msg.d);
              }
            });
          });
        });

    Code HTML4Strict:
            <input type="text" size="20" name="USZip" id="USZip" />
            <div id="Result">Click Here!</div>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ajax cannot be used to call a different domain.

    The most common solution is to proxy the request. Basically, you create a serverside script on your own server and have ajax call your own script. This serverside script will then send the request to the other server, and return the result.

    In this specific case, you could just skip the webservice and make your own. You can find free, or cheap zip code databases around the net.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •