简体   繁体   English

Ajax总是出错

[英]Ajax always goes in error

I am trying to call ajax but it always goes in error part. 我正在尝试调用ajax,但它总是出错。 Please help and tell me where I am wrong. 请帮助并告诉我我错了。 I have also tried writing the final value in a text file and it was perfect but don't know why it is not working. 我也尝试过将最终值写入文本文件,这很完美,但是不知道为什么它不起作用。 I have also checked the URL it is also correct. 我还检查了URL,它也是正确的。

PHP Code: 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: 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.");
        }
    });


}

Please help me. 请帮我。

请尝试使用data:{mail_key:mail_key},而不是data:{'mail_key':mail_key},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM