AJAX uses cookie to transmit values

time:14-04-12 forum:PHP tools and code
  http://www.php100.com/html/webkaifa/aja... /2966.html
before you call Ajax, you can write the data through JavaScript, and then you can get the data in it. Send out, so cool!

> -- w -->www.php100.com

client code below. On getXML ()
{
setcookie ($('name').Value, $('val').Value);
oDiv = document.all.mxh.open (.Quot; POST.quot;.Quot; a.php.quot; false)
xh.send (false);
}

function. T; sorry, the loading data failed. Cause:.Quot, xh.statusText
}
}
//author: PHP100 Chinese network www.php100.com

function setcookie. SetTime (d.getTime () cookieexp);
expires =.Quot; expires=.quot; d.toGMTString ().Quot;.Quot;
document.cookie. Examples:.Lt; br/.gt;
.lt; form name=myform.gt;
name:.lt; input id=name value=.quot; variable names can even be Chinese.Quot; Uot; send out data.Quot;.Gt; phperz~com
.lt; input onclick=.quot; if (XH.Amp;.Amp; xh.responseText). N onclick=.quot; alert (document.cookie).Quot; value= display local COOKIE.gt;
.lt; /form.gt; [/code]
print_r ($_COOKIE);
.Gt; [/code]

phperz~com


first. .
Third, using UTF-8 to send data will not be garbled, is the background program does not correct decoding will appear garbled.
Fourth, when Ajax sends data, if Content-Type is modified to application/x-www-form-urlencoded.quot; it must be post, and "too much data often goes wrong" is caused by sending data in GET.
fifth. Functions written in VBScript are used to transform data into GBK encoding (the default encoding of the operating system). If it is coded in Big5 on the traditional system, rather than GB2312, the number of coded characters between them is about 3 times.
sixth, using cookie to send data, one is easy to overflow, and the two is to stop wiping the butt, otherwise the data inside the cookie will be sent in every HTTP request (including pictures and script requests). Three when there are several HTTP requests concurrently, there is no way to specify that the cookie is sent to the HTTP request.

when using AJAX to return a page to GET, the Chinese in the RESPONSETEXT will appear most of the chaotic code. This is because xmlhttp has coded the resposeBody in the decoding test when it handles the returned responseText, and the Chinese character will be displayed correctly when the server is actually sending out the data flow of UTF-8. When the GBK coded stream was sent, it was a mess. The solution is to add a HEADER to the stream sent to indicate what code stream is sent, so that XMLHTTP will not be fooled. Phperz.com

PHP:header ('Content-Type:text/html; charset=GB2312');
ASP:Response.Charset (.Quot; GB2312.quot;)
JSP:response.setHeader.

prev:The solution to the problem of chaotic c... next:Comment on a page without refresh with P...
post comment
Notice



approved   The girl wants to donate the liver t...   The most beautiful adoptive mother i...   What's the use and use of the social...   A glimpse of the Intangible Cultural...   The couple made tea by hand in deep ...
rand   PHP filter replacement output digita...   PHP uses $_GET to get processing cod...   Fourteen experiences in programming ...   Using JSON to implement cross domain...   PHP good verification code
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com