Zoopla Property API Forums

Support

RSS Feed

jQuery and API

    • EdR
    • Topic created 3 years ago

    Has anyone got the API to work with jQuery or javascript? I am struggling. Using the jQuery function $.get (or $.getJSON, or $.ajax) results in a same-origin-policy error. If I use JSONP to get around this, and add "&callback=?" to the query url, I get a parse error from jQuery as the Zoopla API doesn't appear to support callback functions.

    My query is definitely working, and returns all the correct info in JSON format (I can see this using chrome developer tools, or just by pasting the query URL into the browser). However, I cannot get to the data using jQuery as it returns a parse error.

    Message edited by EdR 2 years ago

    Tags

  1. Matt3 years ago

    Hi,

    We don't support any callback functionality, we only return the data associated with the API request in JSON format.

    Have you considered using a wrapper script on your web server? That would allow you to workaround the policy issues.

    Matt

  2. EdR3 years ago

    Thanks Matt - have got there in the end. A very short asp script has done the trick.

  3. pukkafish3 years ago

    Ed, I'm having the same problem as you have. How did you manage to get the data? I would prefer a script in PHP, but if you only have ASP, it might be fine ...

    Thanks

  4. Jof Arnold2 years ago

    Here's an example for you, now that Zoopla supports jsonp:

        $.ajax({
            url: zooplaQueryUrl,
            dataType: "jsonp",
            jsonpCallback: zooplaJsonpFunction,
            success: function(data) {
              console.log("zoopla call : success");
            },
            error: function(jqXHR, textStatus, errorThrown) {
              console.log('zoople call : error ' + textStatus + " " + errorThrown);
            }
        });
    

    Where zooplaQueryUrl is your API query, and zooplaJsonpFunction is the callback that's triggered after receiving the data. Example of zooplaQueryUrl: http://api.zoopla.co.uk/api/v1/property_listings.js?api_key=KEY&radius0.5&listing_status=rent&postcode=e28aa&page_size=20&jsonp=zooplaJsonpCallback

    Be careful with https versus http - might trip you up. Note the callback must be appended to the end of the URL as shown and must match the one in the options object you construct.

    Hope that helps

[ Page 1 of 1 ]