From what I could tell is that your server doesn't support JSONP with their requests. For instance
var getUrl = 'http://webapp.armadealo.com/home.json';
$.ajax({
url : getUrl,
type : 'GET',
dataType : 'jsonp text',
jsonp: 'jsonp',
crossDomain : true,
success: function() { console.log('Success!'); },
error: function() { console.log('Uh Oh!'); },
});
This would say SyntaxError: invalid label
. The return as you have it is not properly formatted JSONP. It has to be wrapped to work as JSONP because jQuery requires it.
So what you're getting back is correct, but it's not what you need. What you need for JSONP calls would look like this:
functionName({
"mall": {
"name": "South Shore Plaza",
"city": "Braintree",
"directory": "/assets/directory/0000/0094/show_floorplan.aspx",
"postal_code": "02184",
"street": "250 Granite St",
"lng": -71.023692,
"id": 147,
"phone": "(781) 843-8200",
"lat": 42.218688,
"state": "MA"
}
});
... since what comes back currently is not valid JavaScript (by itself, and that's what it is), and that's how JSONP works, the response actually needs to be executable JavaScript.
You can get the same error by just plopping that code straight in your page in a <script>
block.
If you're just after the embedding piece of data, I recommend a plugin like jQuery-oembed, to do that. If you're after the data, you'll need something on your server to process the JSON, then get the data from your server after that.
For example
so let’s say we would like to make a cross-domain using jQuery. Here is how the jQuery $.ajax
call should look like:
$.ajax({
dataType: 'jsonp',
data: 'id=test',
jsonp: 'jsonp_callback',
url: 'http://www.differentdomain.com/get_data.php',
success: function () {
// do something
},
});
Now on the server side (in the get_data.php file) we have to get the callback name and send the data in JSON format wrapped in the callback function.
Something like this:
<?php
$jsonp_callback = $_GET['jsonp_callback'];
$data = array('1','2','3');
echo $jsonp_callback . '('.json_encode($data).');';
?>
JSONP can only be used if and when the server properly embed the response in a JavaScript function call.