阿贾克斯柱式不会将数据发送到PHP页面 [英] Ajax Post Type will not send data to php page

查看:130
本文介绍了阿贾克斯柱式不会将数据发送到PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下形式供用户是在根目录下的文件forgotten.php内重置密码。

I have the following form for users to reset their password it is within the file forgotten.php in the root directory.

<form id="pass_form" action="" method="post" name="pass_form">
  <label>Username:</label>
  <input type="text" class="blank" name="name" id="name" value="Trader Username" data-default="Trader Username" data-message="Please enter your username..."> *<br>
  <input class="sub-btn" type="submit" value="Submit">
</form>

我要发布用户名INC / sendreset.php所以我有以下阿贾克斯JS / scripts.js

I would like to post the username to inc/sendreset.php so I have the following Ajax in js/scripts.js

    $("#pass_form").validator({
    offset: [0, 354],
    position: 'center left',
    messageClass: 'conerror'
}).submit(function(e) {
    if (!e.isDefaultPrevented()) {
        var form = $(this);
        var serdata = form.serialize();
        $.ajax({
            type: "POST",
            url: "sendreset",
            data: serdata,
            cache: false,
            success: function (html) {
                log('inside ajax sendreset', this, arguments);
                $('#pass_form').fadeOut(400,function(){
                    if (html=="0") {

                    } else {
                        $('#pass_form').html('<p>The password reset instructions have been sent. Please check your email.</p>');
                    }
                    $('#pass_form').fadeIn();
                });
            },
            error: function (err) {
                log('error inside ajax sendreset', this, arguments);
            }
        });
        //$('#pass_form').fadeOut(400);
        e.preventDefault();
    }
});

然而,它似乎并没有发布用户名到文件中。该INC / sendreset.php如下:

However it does not seem to post the username into the file. The inc/sendreset.php is as follows

<?php
        require_once('./library.php');
        require_once('./PHPMailer/class.phpmailer.php');

        $Trader = new CompanyTrader();

        $resetdata = $Trader->resetTrader($_POST['name']);
        print_arr($resetdata);

        //more php which isn't relevant
?>

我知道文件INC / sendreset.php工作,当我在文件中使用$ _GET ['名称']我用INC / sendreset.php?NAME =用户名的数组返回相关的用户。它不从forgotten.php使用Ajax虽然工作。请帮帮忙!

I know the file inc/sendreset.php works as when I the file to use $_GET['name'] and i use inc/sendreset.php?name=username the array is returned for the relevant user. It does not work from forgotten.php using Ajax though. Please help!

推荐答案

我真的认为这是错误的:

i really think this is wrong:

url: "sendreset",

尝试用一个相对或绝对URL如 http://mysite.com

这篇关于阿贾克斯柱式不会将数据发送到PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆