手记

jQuery ajax 跨域请求

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+")");


0人推荐
随时随地看视频
慕课网APP