jquery ajax PHP Save data and return value

Source: Internet
Author: User

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>jquery Ajax PHP to save the data and return the value </title>
<script language= "Web Effects" >
function Addborough () {
var name = document.getElementById (' Addboroughname '). Value;
var area_id = document.getElementById (' Cityareaid '). Value;
var cid = document.getElementById (' Cityid '). Value;
var address = document.getElementById (' addboroughaddr '). Value;
var type = document.getElementById (' Addboroughtype '). Value;
alert (Cityid);
Return
if (!name | |!area_id | |!address | |!type) {
Alert ("Please fill out the information");
return false;
}

$.post (' Ajax.php?action=saveborough ', {borough_name:name,cityarea_id:area_id,borough_address:address,cityid:cid , Borough_type:type},function (data) {
return cell ID
if (data ==0) {
Alert (' Add error ');
return false;
}
if (Data.indexof (' | ')) {
var temp = data.split (' | ');
if (Temp[0] < 0) {
Alert ("Add Error");
return false;
}
if (temp[1] = =-1) {
Alert ("you added already existing");
}
Window.parent.addtoboroughitem (temp[0],name,address);
Window.parent.tb_remove ();
}else{
Alert (' Add error ');
return false;
}
});

return false;
}
</script>

<body>
<form action= "" method= "Post" name= "Mydataform" id= "Mydataform" >
<p>
<label> name:</label>
<input type= "text" id= "Addboroughname" name= "addboroughname" class= "input" value= ""/>
</p>
<p>
<label> Area:</label>
<span style= "Display:none;" >
<select name= "Cityid" id= "Cityid" onchange= "Changelocation" (document.mydataform.cityid.options[ Document.mydataform.cityid.selectedindex].value) ">
<option value= "" >--Unlimited--</option>
<option value= "1" > Beijing </option>
</select>
</span> &nbsp;&nbsp;
<select name= "Cityareaid" id= "Cityareaid" >
<option value= "0" >--Unlimited--</option>
</select>
</p>
<p>
<label> Address:</label>
<input type= "text" id= "addboroughaddr" name= "addboroughaddr" class= "input" size= "value=" "/>" "
</p>
<p>
<label> Download:</label>
<select id= "Addboroughtype" name= "Addboroughtype" class= "select" >
<!--{html_options options= $borough _type_option selected= $borough. Borough_type}-->
</select>
</p>
<p>
<input type= "button" id= "AddButton" value= "Add" onclick= "return Addborough ()"/>
</p>
</form>
</body>


ajax.php

$v = $_post[' addboroughname '];

if (not null) {
if (saved successfully) {
echo $borough _id. "| 1 ";
}else{
echo 0;
}
}else{
echo $exest _id. "| -1 ";
}

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.