Home > CMS Tutorial > DEDECMS > body text

How to implement DedeCMS digg Ajax cross-domain

藏色散人
Release: 2019-12-18 10:11:08
Original
2394 people have browsed it

How to implement DedeCMS digg Ajax cross-domain

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:

Copy after login

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 
});
Copy after login

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
历史访问人数:点击test按钮获取数据
今天访问人数:点击test按钮获取数据
阳光指数:点击test按钮获取数据
爱心指数:点击test按钮获取数据
雨露指数:点击test按钮获取数据
营养指数:点击test按钮获取数据
花匠级别:点击test按钮获取数据

Copy after login

You can copy the above code to your local computer and open it with IE or FIREFOX. Click the button. I found that the dynamic effect was achieved without refreshing the page, and the returned data was obtained across domains. Everyone knows that JAVASCRIPT cannot be accessed across domains, which is amazing. . . . Careful study of the code revealed the wonders

This code:

 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";
Copy after login

The browser obtained the SCRIPT element through DOM parsing, and then added the ID and SRC attributes. Here is the official explanation of the SRC attribute of the SCRIPT element from the W3C specification: The script element allows authors to include dynamic script in their documents. When the src attribute is set, the script element refers to an external file. The value of the attribute must be a URI (or IRI). If the src attribute is not set, then the script is given by the contents of the element. Interpreted as: If the SRC attribute of the SCRIPT tag is defined, the SCRIPT tag refers to an external file, and the attribute value Must be a URL. This means that SCRIPT will reference the contents of the file from this URL. Everyone accesses this link in the browser: http://g2.qzone.qq.com/fcg-bin/cgi_emotion_list.fcg?uin=123456 This URL similar to JAVA's SERVLET returns the following data: visitCountCallBack({"visitcount": 65188579, "dayvisit":8658, "spacemark":0, "markchange":0, "sun":1680, "love":478, "rain":1680, "nutri":1450, "level":5, "gardener":1});This string is a JAVASCRIPT function, and the input is a JSON string. When this data is returned, another JAVASCRIPT function above is called: 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]; 
} 
}
Copy after login

In the function, the JSON data returned by the innerHTML bar is used to fill the BODY, achieving asynchronous access to the data without refreshing the page. Effect. There is another key question: http://g2.qzone.qq.com/fcg-bin/cgi_emotion_list.fcg?uin=123456 is a URL of QQ space (uin is QQ number, you can enter your own QQ number to try (Test), JAVASCRIPT calls data from other domains. This method is relatively simple to obtain data, and can also access data across domains. It is more suitable for some simple, small non-refresh effects. I am a little worried that if the browser is updated one day and denies this access method, the data obtained in this way may become unusable. I suggest that everyone use this method with caution! ! !

The above is the detailed content of How to implement DedeCMS digg Ajax cross-domain. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!