In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to solve the cross-domain problems of Ajax. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
Cross-domain problem
As shown in the figure, this is a local php file (no framework) requested through the jquery encapsulated ajax, and the console prompts that the CORS policy has blocked the "null" from the source: the "access control allowed source" header does not exist on the requested resource.
Solution
Set the header
Header ("Access-Control-Allow-Origin: *"); allow all domain name requests
Header ("Access-Control-Allow-Origin: http://127.0.0.1"); allows a domain name request
Request to enter the error question successfully
This is mostly because you are required to return data in json format, but the actual data returned is not correct json data.
Var data = {parent:1} $.ajax ({type: "POST", url: "http://127.0.0.1", dataType:'json', success: function (response,index,obj) {console.log (obj.done (function () {/ / callback alert (" $.get succeeded ");})); console.log (index) / / log success console.log ("success", response); / / data returned from a successful request}, error (res) {console.log ("failure", res);}})
The first letter of Ajax is the first letter of asynchronous, which means that all operations are parallel and the order in which they are completed is unrelated. The async parameter of $.ajax () is always set to true, which indicates that other code can still execute after the request starts. Setting this option to false is strongly discouraged, which means that all requests are no longer asynchronous, which can cause browsers to lock up.
These are all the contents of the article "how to solve the Cross-domain problem of Ajax". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.