DedeCMS digg How to implement cross-domain Ajax?
Because the web project uses a second-level domain name, the original digg cannot be used normally. After careful analysis, it was found that Ajax JS submission cannot be submitted across domains.
Recommended study: 梦Weavercms
provides the following solutions:
@written by etongchina 2009-02-06 19:00
Implementation plan: similar to json implementation
Implementation principle: js allows imported remote files (js) to operate local data
Specific method: (with 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 in the local html or js file:
<SCRIPT LANGUAGE="JavaScript"> 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 ; //需要统计的php页面的 src } 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.innerHTML=data[i]; //一些代码去修改本地html } } </script>
Modify the following code: Like
is: Like
2. Access remote files:
Remote file (http://www.xxx.com/../dig.php?type=digg&tid=456) returns similar code:
visitCountCallBack({ "visitcount":135 });
The above code is equivalent to the remote file calling the local function: visitCountCallBack
In this way, you can use remote return data to dynamically modify local files.
3. Summary:
Regarding this solution, it is currently feasible, but some people think it will be outdated. I don't think there will be any problem of JS overstepping its authority.
I have an AJAX-like application here. The key technology is the application of the src attribute of the