Some tips on PHP +jquery coding

  • 2020-03-31 21:15:53
  • OfStack

PHP files should be saved as ANSI, and code calls are available when encoding is changed.
 
//The code is gb2312. Currently, most web pages still use gb2312, and a few use utf-8.
//www.baidu.com actually use both, so how to read baidu's web pages are no problem
header('Content-Type: text/html; charset=gb2312'); 
//Encoding to utf-8
header('Content-Type: text/html; charset=gb2312'); 
//The encoded XML is utf-8, but it seems to work
header('Content-Type: text/xml; charset=utf-8'); 


Jquery client handling
The client web page is saved as utf-8, and the following Settings are made, and the database is also set as utf-8, so that data transmission with ajax is not easy to garble code.
 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 


 
//It is recommended to use $. Get (),$. Post (), as far as possible without $.
//:) but if you study the source code of jquery, that's another story!
$.get("test.php", function(data){ 
alert("Data Loaded: " + data); 
}); 
$.get("test.cgi", { name: "John", time: "2pm" }, 
function(data){ 
alert("Data Loaded: " + data); 
}); 
$.post("test.cgi", { name: "John", time: "2pm" }, 
function(data){ 
alert("Data Loaded: " + data); 
}); 

Personal experience, imperfections, please put forward, I will listen to the correction. Aim at mutual encouragement!

Related articles: