我需要一些建议/帮助,我有两个值传递到另一个页面,但只有我的产品ID通过,我的电子邮件值在我的数据库中为空。如果有人可以在这里提供帮非常感谢。
<script language="javascript" type="text/javascript">
var httpObject=false;
if(window.XMLHttpRequest){
httpObject = new XMLHttpRequest();
}else if(window.ActiveXObject){
httpObject = new ActiveXObject("Microsoft.XMLHttp");
}
function ajax_post(id,na){
var queryString = "?data1=" + id ;
queryString += "&data2=" + na;
httpObject.onreadystatechange = function(){
if(httpObject.readyState == 4 && httpObject.status == 200){
var error = document.getElementById('error');
var response = httpObject.responseText;
alert(response);
}
}
httpObject.open("GET", "espaceproductinsert.php"+queryString ,true);
httpObject.send(null);
}
</script>
第1页
<?php
$sql = mysql_query ("SELECT * FROM espaceproduct WHERE email = 'jaychou@hotmail.com' ");
$row = mysql_fetch_array($sql);
$id = $row['id'];
echo $email = $row['email'];
echo '<a href="#" onClick="ajax_post('.$id.','.$email.')" >'. $id .'</a>'."<br/>";
?>
这两个值都应插入espaceproductinsert.php
$csg = $_GET['data1'];
$add = $_GET['data2'];
$sql2 = mysql_query ("INSERT INTO espaceproduct (storename,productname) VALUES ('$csg','$add') ");
答案 0 :(得分:0)
你的行中onclick
而不是onClick
:
echo '<a href="#" onClick="ajax_post('.$id.','.$email.')" >'. $id .'</a>'."<br/>";
看看是否清除了它。
答案 1 :(得分:0)
我认为ajax_post函数中的代码序列不正确,你应该改变这样的序列
httpObject.open("GET", "espaceproductinsert.php"+queryString ,true);
httpObject.onreadystatechange = function(){
if(httpObject.readyState == 4 && httpObject.status == 200){
var error = document.getElementById('error');
var response = httpObject.responseText;
alert(response);
}
}
httpObject.send(null);
进行此更改并检查