jQuery ajax 跨域请求

2023-06-13,,

jQuery官方apigetJSON(http://api.jquery.com/jQuery.getJSON/)的说明中有这样一段

AdditionalNotes:

  • Duetobrowsersecurityrestrictions,most"Ajax"requestsaresubjecttothesameoriginpolicy;therequestcannotsuccessfullyretrievedatafromadifferentdomain,subdomain,orprotocol.

  • ScriptandJSONPrequestsarenotsubjecttothesameoriginpolicyrestrictions.

    所以一般的ajax跨域请求返回不了什么东东的。只有script和jsonp两种可以返回。

    举例:

    对于jsonp,有url?jsonCallBack=?

    在后台,如jsp中如最后这样写Stringjson="{\"name\":\"LP\"}";out.print("jsonCallBack("+json+")");

《jQuery ajax 跨域请求.doc》

下载本文的Word格式文档,以方便收藏与打印。