SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery API calls on local server

    My company is in the process of switching to an online booking system and our database admin (who also created the booking program we use in house currently) has set up the api and we are hoping to test it in house before making it public facing.

    My computer and the server with the database/program are both on the same network in house and when I type in the url he gave me to access it directly into the browser i get the data back fine(in xml in Chrome and FF, IE returns it in json). But when I try and write and api call in jquery to test on the website(local machine copy) I get nothing back. No errors in the console, nothing. I pretty new at javascript and jquery and the few api calls I've written have been to live websites (twitter, flickr, etc) so you'll have to bear with me. I've tried $.getJSON method as well as fetching it in xml(and json and jsonp) using $.ajax.

    Obviously I'm not really sure what I'm doing here so an help would be great. I would just ask the guy who built it but he left for a week and I was hoping to start messing with it now. Thanks, below is the api call in it's latest iteration

    Code JavaScript:
    <script>
    (function(){
     
    	$.ajax({
    	    type:'Get',
    	    url: "http://tmapi.huts.org/api/businessinfo",
    	    dataType: 'xml',
    	    crossDomain: false,
    	    error: function() { alert("No data found."); },
                success: function(data){
    	    console.log(data);
    	    }
    	});
    });
    </script>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,053
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    You are likely running into the same origin policy restriction. The only way around it is to use a server side proxy located one your local domain. The server side proxy would than make the request directly to the API rather than JavaScript.
    The only code I hate more than my own is everyone else's.


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
  •