douliaodan2738 2016-09-26 18:02
浏览 9

在php中捕获ajax发布的值

I have a form that uses jquery form validation to change the email of a user. The problem that im having is when the user submits the values are posted but i cant capture it in my php file. It always prints empty

Below is my code

$("#change_email").validate({
    rules: {
        "new_email": {
            required:true,
            email: true
        },
        "confirm_email": {
            required: true,
            equalTo : "#email"
        }
    },
    messages: {
        "new_email": {
            required: "required",
            email: "invalid"
        },
        "confirm_email": {
            required: "not match",

        }
    },
    submitHandler: function (form) { 
        var formd = $(form).serialize();
        $.ajax({
            url: 'http://localhost/secular/change_email',
            type: 'POST',
            data: formd,
            async: false,
            success: function(data) {
                alert(data);
            },
            error: function(data){
                console.log("error");
            });
         return false;
    }
});

HTML

<form id="change_email">
    <div class="form-group">
        <label class="control-label col-sm-3">New Email :</label>
        <div class="col-sm-4">
            <input type="text" name="new_email" id="email" class="form-control" required>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-3">Confirm Email:</label>
        <div class="col-sm-4">
            <input type="text" name="confirm_email"  class="form-control" required>
        </div>
    </div>
    <input class="btn btn-primary" value="Save" type="submit">
</form>

PHP

function change_email()
{
    echo $email = $this->input->post('new_email');
}

When I check on firebug it posts as below

new_email=test%40test.com&confirm_email=test%40test.com

Can someone tell me what am I doing wrong here?

EDIT: Look here in Firebug, especially the response:

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求指导ADS低噪放设计
    • ¥15 CARSIM前车变道设置
    • ¥50 三种调度算法报错 有实例
    • ¥15 关于#python#的问题,请各位专家解答!
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存