我试图调用ajax但它总是出错部分。请帮帮我告诉我哪里错了。我也尝试在文本文件中写入最终值,它很完美但不知道为什么它不起作用。我还检查了URL也是正确的。
PHP代码:
public function checkLockBeforeSend()
{
$mail_key = $_POST['mail_key'];
$this->load->model('dl_master/email_compose');
$result = $this->model_dl_master_email_compose->checkLock($mail_key);
if($result['isopen'] == 1 && $result['openedby'] != $_SESSION['user_id'])
{
$this->load->model('dl_common/commonutil');
$userResult = $this->model_dl_common_commonutil->getUserById($result['openedby']);
$userName = $userResult['firstname'] . " " . $userResult['lastname'];
$html = $userName;
}
else
{
$html = "Empty";
}
/* Just to check what value is coming */
$fp = fopen("C:\\test.txt","w");
fwrite($fp,$html);
fclose($fp);
echo $html;
}
Ajax功能:
function checkLockBeforeSend(mail_key)
{
var ajaxUrl = "index.php?route=dl_master/email_compose/checkLockBeforeSend&token=" + token;
$.ajax ({
url:ajaxUrl,
type:'post',
dataType: 'html',
data:{'mail_key':mail_key},
success:function (result)
{
alert(result);
if(result.trim() != "Empty")
{
finalResult = confirm(result);
}
},
error: function ()
{
alert("An error occurred.");
}
});
}
请帮帮我。
答案 0 :(得分:1)
请尝试data:{mail_key:mail_key},
而不是data:{'mail_key':mail_key},
。