views:

39

answers:

2

Trying to make a JSONP request to yellowapi (Yellow Pages), even specifying a callback is giving me the "invalid label" error. Here is what I have so far:

$.ajax({
dataType: 'jsonp',
 cache : false,
 url: "http://api.sandbox.yellowapi.com/FindBusiness/",
 data : "apikey="+testingPurposes+"&what="+what+"&where="+where+"
    &fmt=JSON&pgLen=1&UID=127.0.0.1&callback=?",
 success: function (data) {
   alert(data)
 }
});

It returns the right result in JSON format, but it doesn't have the "json12345678" callback at the start. Giving me an "invalid label" error.

What are my options to fix this?

P.S. All the variables are defined, apikey will be removed later.

+1  A: 

If it doesn't have the callback at the start, it would be an issue with the API you are consuming, not an issue with your code. Have you confirmed it supports JSONP?

Ryan Tenney
I figured that, but didn't know if there was a way around it. I haven't confirmed that their is a callback, but at this point I assume no.
wutanggrenade
A: 

The docs say that the the supported formats are json and XML, not jsonp. You may then have trouble consuming this data due to cross-site scripting restrictions built into browsers. (When I've had to do this kind of thing before I usually generate a proxy service on my own server that makes the requests to the yellowapi.com from PHP, as PHP doesn't have those cross-site restrictions)

Michael Anderson
Another advantage of making the request from your own server is you dont need to make the apikey public - otherwise any user of your page can see the apikey - not good.
Michael Anderson
I was hoping to cut out PHP, but worst case scenario I'll have to go that route.
wutanggrenade
I agree, this was just for testing purposes, I'd never have the apikey left there
wutanggrenade