【发布时间】:2012-03-08 21:09:57
【问题描述】:
我正在向 php 文件发送一个 ajax 请求,如下所示:
function checkDB(code, userid)
{
$.ajax({
type: "POST",
url: "<?php bloginfo('template_url'); ?>/profile/check_code.php",
data: 'code='+code+'userid='+userid,
datatype: "html",
success: function(result){
if(result == 0)
{
$('#success').html( code + ' has been redeemed!');
// alert('success');//testing purposes
}
else if(result == 2)
{
$('#err').html( code + ' already exists and has already been redeemed....');
//alert('fail');//testing purposes
}else if(result == 1){
$('#err').html( code + ' redeem code doesnt exist');
}
alert(result);
}
})
}
这是在提交时调用函数发送的,如下所示:
<form method="post" class="sc_ajaxxx" id="sc_add_voucherx" name="sc_ajax"
onsubmit="checkDB(document.sc_ajax.sc_voucher_code.value, <?php echo $user_id ?>); return false;">
</form>
问题是用户 id php 变量没有被 ajax 发送到 check_code.php 页面。或者至少我似乎无法将 id 回显到页面。
这是将多个值传递到服务器端页面的正确方法吗?如果没有传递用户 ID,只需传递代码就可以正常工作。
谢谢大家:)
【问题讨论】: