Hello,
I came across this example regarding JSONP and getting results back from a different domain than say one that you control, kind of like a 3rd party API.
The example is at
http://www.jquery-tutorial.net/ajax/requesting-a-file-from-a-different-domain-using-jsonp/The question I have is the author goes to great lengths to discuss JSONP and then you find the docs for $.get()
at:
http://api.jquery.com/jQuery.get/ <-- For get method
And no place in the $.get method() is there a datatype called jsonp, only json. Ironically if you set the datatype to jsonp jQuery does not complain, despite the fact this appears to be not a valid datatype.
If you paste this code below into your localhost it should run fine.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>promise demo</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<ul id="ulUsers"></ul>
<script type="text/javascript">
$(function()
{
$.get
(
"http://tests.jquery-tutorial.net/json.php?callback=?",
function(data, textStatus)
{
$.each(data, function(index, user)
{
$("#ulUsers").append($("<li></li>").text(user.name + " is " + user.age + " years old"));
});
},
"json"
);
});
</script>
</body>
</html>
<!--
$.get(URL,data,function(data,status,xhr),dataType)
dataType = Type: String
The type of data expected from the server.
Default: Intelligent Guess (xml, json, script, or html).
-->
So the question is why are there so many articles on JSONP and cross-domain and then in $.get() JSONP is largely ignored?
Jim