前端之家收集整理的这篇文章主要介绍了
Ajax应用,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<span style="color:#ff0000;">ajax2.PHP内容</span>
<span style="color:#ff6666;background-color: rgb(255,255,255);"><?PHP
/*
**************************
(C)2010-2014 chinaweber.com
update: 2015-8-15 21:59:40
person: xamin
**************************
*/
/*
*持续进修续费返回json
*/
require_once(dirname(__FILE__).'/include/config.inc.PHP');
$r = $dosql->GetOne("SELECT * FROM `#@__goods` WHERE id=".$id);
$str = array("payfreight"=>$r['payfreight'],"salesprice"=>$r['salesprice'],"title"=>$r['title'],"weight"=>$r['weight']);
echo json_encode($str); //将数组转成js可识别的json格式
?></span>
<script type="text/javascript">
function getInfo() {
//var id = document.getElementById('goodsid').value;
//alert(id);
$.ajax({
url : 'ajax2.PHP',type : 'post',data : {'id':$("#goodsid").val(),'username':$("#username").val()},dataType:'html',//beforeSend:function(){checkpass()},success:function(data){
//alert(data);
//将PHP返回的json转成与之对应的javascript对象方便读取
rdata = $.parseJSON(data);
//alert(rdata);
//var rdata = {"username" : "mingtao","pass" : "123456"}
//alert(rdata.weight);
document.getElementById('payfreight').value = rdata.payfreight;
document.getElementById('salesprice').value = rdata.salesprice;
document.getElementById('totalprice').value = rdata.salesprice;
document.getElementById('sprice').value = rdata.salesprice;
document.getElementById('protitle').value = rdata.title;
document.getElementById('overduedate').value = rdata.weight;
}
});
}
</script>
<select name="goodsid" id="goodsid" onChange="getInfo()">
<option value="">請選擇</option>
<?PHP
$brandid = 3; //3是本土活动
$sql = "SELECT * FROM `#@__goods` WHERE delstate='' AND checkinfo=true AND brandid=".$brandid." ORDER BY orderid DESC";
echo $sql;
$dosql->Execute($sql);
while($row = $dosql->GetArray()) {
//$payfreight = $row['payfreight'];
//$salesprice = $row['salesprice'];
//$protitle = $row['title'];
//$overduedate = $row['weight'];
?>
<option value="<?PHP echo $row['id'] ?>"><?PHP echo $row['title'] ?></option>
<?PHP
}
?>
</select>
原文链接:https://www.f2er.com/ajax/162959.html