How to realize DedeCMS digg Ajax Cross-Domain
This article is to share with you about how DedeCMS digg Ajax is implemented across domains. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
How to implement DedeCMS digg Ajax cross-domain?
Because the second-level domain name is used in the web project, the original digg can not be used normally. After careful analysis, it is found that Ajax JS submission can not cross-domain problem.
The solutions provided are as follows:
@ writen by etongchina 2009-02-06 19:00
Implementation: similar to json implementation
Implementation principle: js allows the introduction of remote files (js) to manipulate local data
Specific method: (take http://news.xxx.com/200812/25-4653.html as an example)
1. Modify the js calling part of http://news.xxx.com/200812/25-4653.html
Write to a local html or js file:
Function _ Digg (type,tid) {var s = document.createElement ("SCRIPT"); s.id = "cgi_emotion_list"; document.getElementsByTagName ("HEAD") [0] .appendChild (s); s.src = "http://www.xxx.com/../dig.php?type="+type+"&tid="+tid; / / src} function visitCountCallBack (data) {document.getElementsByTagName (" HEAD ") [0] .removeChild (" cgi_emotion_list ") of the php page to be counted. For (var i in data) {var e = document.getElementById (I); if (e) e [XSS _ clean] = data [I]; / / some code to modify the local html}}
Modify the following code: top
For: top it up.
two。 Access remote files:
The remote file (http://www.xxx.com/../dig.php?type=digg&tid=456) returns something like this:
VisitCountCallBack ({"visitcount": 135})
The above code is equivalent to a remote file calling a local function: visitCountCallBack
In this way, it is possible to use remote return data to dynamically modify local files.
3. Summary:
With regard to this scheme, it is feasible at present, and some people think that it will be out of date. I don't think it will give rise to the problem of ultra vires of JS.
I have an AJAX-like application here, and the key technology is the application of the src attribute of the tag.
Please take a look at the following HTML code
Asynchronous json example function test () {var s = document.createElement ("SCRIPT"); s.id = "cgi_emotion_list"; document.getElementsByTagName ("HEAD") [0] .appendChild (s); s.src = "http://g2.qzone.qq.com/fcg-bin/cgi_emotion_list.fcg?uin=123456"; / / test=function () {};} function visitCountCallBack (data) {document.getElementsByTagName (" HEAD ") [0] .removeChild (document.getElementById (" cgi_emotion_list ")) For (var i in data) {var e = document.getElementById (I); if (e) e [XSS _ clean] = Data [I];}}