I have a small problem. I'm sending an AJAX call to retrieve JSON using a php proxy hosted on my website. It's working great, but whenever there's an argument with a space, it gets encoded as %20 and I get back:
{"status":{"http_code":400},"contents":"<html><body><h1>400 Bad request<\/h1> Your browser sent an invalid request. <\/body><\/html> "}
How else can I encode the space to make this work? Here's an example of the bad request URL. The space appears in the city name "Santa Monica":
http://www.mysite.com/ba-simple-proxy.php?url=https%3A%2F%2Fwww.eventbrite.com%2Fjson%2Fevent_search%3Fcity%3DSanta%20Monica%26region%3DCA%26country%3DUS%26within%3D15%26within_unit%3DM%26start%3D2013-12-10%26max%3D50
EDIT: AJAX request here:
$.ajax({
type: 'GET',
url:'http://www.mysite.com/ba-simple-proxy.php?url=https%3A%2F%2Fwww.eventbrite.com%2Fjson%2Fevent_search%3Fcity%3DSanta%20Monica%26region%3DCA%26country%3DUS%26within%3D15%26within_unit%3DM%26start%3D2013-12-10%26max%3D50',
dataType: "json",
success: jsonFunction,
error: jsonFunction
});
Don't try to encode the data yourself in the URL. Let jQuery do it for you.
var search = {
city: 'Santa Monica',
region: 'CA',
country: 'US',
within: 15,
within_unit: 'M',
start: '2013-12-10',
max: 50
};
var url = 'https://www.eventbrite.com/json/event_search?'+$.param(search);
$.ajax({
type: 'GET',
url:'http://www.mysite.com/ba-simple-proxy.php',
data: {
url: url
},
dataType: "json",
success: jsonFunction,
error: jsonFunction
});
you can use urldecode() function it will help you