Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to access XML data across domains by Ajax

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how Ajax accesses XML data across domains". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how Ajax accesses XML data across domains" can help you solve the problem.

XML data cannot be read through Ajax cross-domain requests on the client by default. The general practice is to write a simple agent program on the server to read the remote XML data to the local server first, and then the client requests through Ajax from the local server. Since we cannot make any settings or modifications to the environment in which the data source is located, it is difficult to bypass this problem only through the client code. However, if the requested data is not a XML but a JSON object or JavaScript function, it can be easily solved by the JSONP method, and the returned result can be obtained by directly calling the JQuery.getJSON () method in the callback function. If you want to use JSONP, you can append the query parameter "& callback=?" to the specified URL.

$(document) Ready (function () {

$.getJSON ("http://www.example.com/getdata", function (data) {

Console.log (data)

})

})

$(document) Ready (function () {

$.getJSON ("http://www.example.com/getdata2?callback=?", function (data) {

Console.log (data)

})

})

This is the end of the introduction to "how Ajax accesses XML data across domains". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report