<!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>
<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 ";
}