关于jQuery中$.ajax()跨域

今天研究了一些用jquery $.ajax跨域的方法,总结了一些注意事项如下:

     首先,跨域JSONP不是AJAX。它不使用XMLHttpRequest。只不过是一个动态脚本元素加载JavaScript代码。   

Cross-domain JSONP isn’t AJAX at all. It doesn’t use XMLHttpRequest. It’s nothing more than a dynamic script element that loads JavaScript code.

You can’t do a POST with a dynamic script element. Where would you put the POST data?

I don’t know what the $.ajax code is trying to do – maybe it should fail in a more informative way. It will fail one way or another regardless.

 

     其次,要使用get访问(type:get)。

 

     第三,async要为true(默认为true) 。

       Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation.

 

     第四,cache要设为false(默认为true)。

       Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true.

 

     最后设置一下jsonp和jsonpCallback就ok了。

posted @   赵治鲁  阅读(1166)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示