Ajax no refresh update data and no refresh submit code

Source: Internet
Author: User
Tags mysql tutorial php tutorial
if ($_post | | $_get)
{
$CN = MySQL tutorial _connect (' localhost ', ' root ', ' 123456a ');
$data = $_post[' data '];
$sql = "Update test set data= ' $data ' where id=1";
Mysql_db_query (' db ', $sql, $CN);
}
?>
<form name= "Form1" method= "Post" action= "" >
<label>
<input name= "DataValue" type= "text" id= "Data" >
</label>
<label>
<input type= "button" Name= "Submit" value= "Save Data" onclick= "JavaScript Tutorial: Ajaxsava ();" >
</label>
<div id= "DV111CN" ></div>
</form>

<script language= "JavaScript" >

var xmlhttp;

Function Ajaxsava () {
 var url = "ajaxsava.php tutorial";
 var Obao = Createhttpobject ();
 var Data = Form1.datavalue.value;
 alert (data);
 obao.open ("POST", url,true);
 obao.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
 obao.onreadystatechange = function () {onreadystatechng ();};
 obao.send ("Data=" +data);
}

function onreadystatechng () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
Document.getElementById.innerHTML = unescape (Xmlhttp.responsetext);
}
else {
document.getElementById (' DV111CN '). InnerHTML = "failed, <a href= ' javascript:; ' onclick= ' checkrep (this); ' > re-submit </a> ";
}
}else{
document.getElementById (' DV111CN '). InnerHTML = "}
}

function Createhttpobject () {


try {
XMLHTTP = new ActiveXObject ("Msxml2.xmlhttp");
}
catch (e) {
try {
XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (e) {
XMLHTTP = false;
}
}

if (!xmlhttp && typeof xmlhttprequest!= ' undefined ') {
try {
XMLHTTP = new XMLHttpRequest ();
}
catch (e) {
Xmlhttp=false;
}
}

if (!xmlhttp && window.createrequest) {
try {
XMLHTTP = Window.createrequest ();
}
catch (e) {
Xmlhttp=false;
}
}

return XMLHTTP;
}

</script>

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.