ajax函数的标头是:jQuery.ajax( url [, settings ] )
在文档中说需要URL,为什么在示例中仅提供“设置”?
$.ajax({
type: "GET",
url: "test.js",
dataType: "script"
});
Right below that, you'll see the other syntax for $.ajax
, where just a settings object is passed, including the URL.
They provide two method signatures
jQuery.ajax( url [, settings ] )
jQuery.ajax( [settings ] )
I really only saw one example that didn't use the url (the one using the statusCode setting):
$.ajax({
statusCode: {
404: function() {
alert("page not found");
}
}
});
I it seems they purposely omitted the url to show you the action specified after the url is inevitably not found (since no url is specified). You need to specify the url because whenever you make a server request (whether it be using AJAX, or synchronous-old fashion way) you need to tell the browser who to send the request to. Almost all the examples I saw in the jQuery documentation page have a specified URL or some sort (url: "test.html", url: a_cross_domain_url, url: "http://fiddle.jshell.net/favicon.png"). It's always useful to see all the documentation examples to get a better idea of the syntax and what it does.
URL is not required, if you make call to current page.
From: http://www.sitepoint.com/use-jquerys-ajax-function/
(...) In the second form, the URL is specified in the options parameter,
or can be omitted in which case the request is made to the current page.