Ajax three questions __ajax

Source: Internet
Author: User
Tags domain server

(1) Ajax Chinese problems
In the process of passing a parameter, Chinese characters are encoded in a UTF-8 way.
var url = encodeuri (URL); Note: two times in IE encodeURI
For example, "medium" the Chinese character, will be transmitted by%E4%B8%AD.
On the server side, after taking the parameters. You have to decrypt it.
String old = Request.getparameter ("name");
Then decode it on the server side
String name = Urldecoder.decode (old, "UTF-8");

(2) Ajax cross-domain problem
Same domain: If the HTML code and server code are called the same domain on the same server.
Cross-domain: If the HTML code and server code are not on the same server, it is called Cross-domain.
Cross-domain issues, JavaScript are not allowed to invoke other pages ' objects across domains for security reasons.
Through the IFRAME to achieve a very poor security, easy to lead to viruses and Trojans.
Let the page end program first access the same domain server-side agent, through the agent and remote server
Program interaction. Because the agent is written in Java, all programs can access any remote server.
Client:
function Converurl (URL) {
if (url.substring (0,7) = = "http://") {
Url.replace ("?", "&");
Url= "Proxy?url" +url
}
return URL;
}
Proxy Server side:
(1) Get the client URL and parameter information
(2) Connect by url = new URL (url.tostring ());
URLConnection connection = Connect.openconnection ();
OutputStreamWriter paramout = new OutputStreamWriter (Connection.getoutputstream ());
To access the remote server code, and finally on the proxy server to send processing data through the form of streaming to the browser.

(3) Ajax cache problem
  in Ajax the buffer information for the same IE read browser is not interacting with the server. On the request address
  Plus timestamp, cheated the browser, so that the request address is not the same, do not read the buffer. Send a new request.
 var timestamp = new Date ();
 if (Url.indexof ("?") >=0) {
  url=url+ "&date" +timestamp;
&NBSP} else {
  url= url+ "? Date" +timestamp;
&NBSP
  This guarantees that the browser is not the same every time the request is requested.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.