Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery.load()函数在我的php文件上不起作用_Php_Javascript_Jquery_Web Applications_Web - Fatal编程技术网

jQuery.load()函数在我的php文件上不起作用

jQuery.load()函数在我的php文件上不起作用,php,javascript,jquery,web-applications,web,Php,Javascript,Jquery,Web Applications,Web,我使用jQuery.load()函数的特殊情况是在单击链接后将页面包含到我的站点中。我选择内联编写代码。我有一个用户控制面板,上面有几个按钮,可以链接到编辑信息的页面。我有一个密码和一个设置。我正在努力让这个工作,我会写一个for-each循环应用到我点击的任何链接。我的php文件如下所示: <?php include_once("template/main_site/core/init.php"); protect_page(); if (empty($_POS

我使用jQuery.load()函数的特殊情况是在单击链接后将页面包含到我的站点中。我选择内联编写代码。我有一个用户控制面板,上面有几个按钮,可以链接到编辑信息的页面。我有一个密码和一个设置。我正在努力让这个工作,我会写一个for-each循环应用到我点击的任何链接。我的php文件如下所示:

<?php
    include_once("template/main_site/core/init.php");
    protect_page();

    if (empty($_POST) === false) {
        $required_fields = array('current_password', 'password', 'password_again');
        foreach ($_POST as $key=>$value) {
            if (empty($value) && in_array($key, $required_fields) === true) {
                $errors[] = 'Fields lighted red are required.';
                break 1;
            }
        }

        if (encryptBetter($_POST['current_password']) === $user_data['password']) {
            if (trim($_POST['password']) !== trim($_POST['password_again'])) {
                $errors[] = 'Your new passwords do not match';
            }
            if (strlen($_POST['password']) < 6 || strlen($_POST['password']) >= 32) {
                $errors[] = 'Your new password must be less than 32 characters and more than 6 characters.';
            }
        } else {
            $errors[] = 'Your current password is entered incorrectly.';
        }

    }
?>
    <h1>Change Password</h1>
    <?php
    if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
        echo 'Your password has been changed!';
    } else {
        if (isset($_GET['force']) === true && empty($_GET['force']) === true) {
    ?>
        <p>You must change your password now that you've requested.</p>
    <?php
        }
        if (empty($_POST) === false && empty($errors) === true) {
            change_password($session_user_id, trim($_POST['password']));
            header('Location: changepassword.php?success');
            exit();
        } else if (empty($errors) === false) {
            echo output_errors($errors);
        }
    ?>
    <form action = "" method = "post">
        <ul>
            <li>
                <label>Current Password</label>
                <input required type = "password" name = "current_password" pattern=".{6,32}"/>
            </li>
            <li>
                <label>New Password</label>
                <input required type = "password" name = "password" pattern=".{6,32}"/>
            </li>
            <li>
                <label>Repeat New Password</label>
                <input required type = "password" name = "password_again" pattern=".{6,32}"/>
            </li>
            <input type = "submit" value = "change password"/>
        </ul>
    </form>

<?php
    }
?>
<div id="controls">
    <ul>
        <a id = "changepassword" href = "#login"><li>Change Password</li></a>
        <a href = "#"><li>Edit Profile</li></a>
        <?php if (is_admin()) { ?><a href = "#admin"><li>Administrate</li></a><?php }?>
        <a href = "logout.php"><li>Log out</li></a>
        <div id = "panel"></div>
    </ul>
</div>
<div id = "panel"><?php # include_once('template/main_site/includes/widgets/changepassword.php'); ?></div>

<script>
    $('#changepassword').click(function() {
        var phpFile = 'template/main_site/includes/widgets/' + $(this).attr('id') +'.php';
        $('#panel').html('loading...').load(phpFile);
    });
</script>

修改密码
您必须更改您的密码,现在您已经请求

  • 当前密码
  • 新密码
  • 重复新密码
我把这个php文件包含在一个包含页面中。我还注意到,如果我使用PHPClude包含changepassword.php页面,它将正确加载。我基本上想要与php的include相同的东西,除了jQuery加载

我登录的包含php的文件如下所示:

<?php
    include_once("template/main_site/core/init.php");
    protect_page();

    if (empty($_POST) === false) {
        $required_fields = array('current_password', 'password', 'password_again');
        foreach ($_POST as $key=>$value) {
            if (empty($value) && in_array($key, $required_fields) === true) {
                $errors[] = 'Fields lighted red are required.';
                break 1;
            }
        }

        if (encryptBetter($_POST['current_password']) === $user_data['password']) {
            if (trim($_POST['password']) !== trim($_POST['password_again'])) {
                $errors[] = 'Your new passwords do not match';
            }
            if (strlen($_POST['password']) < 6 || strlen($_POST['password']) >= 32) {
                $errors[] = 'Your new password must be less than 32 characters and more than 6 characters.';
            }
        } else {
            $errors[] = 'Your current password is entered incorrectly.';
        }

    }
?>
    <h1>Change Password</h1>
    <?php
    if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
        echo 'Your password has been changed!';
    } else {
        if (isset($_GET['force']) === true && empty($_GET['force']) === true) {
    ?>
        <p>You must change your password now that you've requested.</p>
    <?php
        }
        if (empty($_POST) === false && empty($errors) === true) {
            change_password($session_user_id, trim($_POST['password']));
            header('Location: changepassword.php?success');
            exit();
        } else if (empty($errors) === false) {
            echo output_errors($errors);
        }
    ?>
    <form action = "" method = "post">
        <ul>
            <li>
                <label>Current Password</label>
                <input required type = "password" name = "current_password" pattern=".{6,32}"/>
            </li>
            <li>
                <label>New Password</label>
                <input required type = "password" name = "password" pattern=".{6,32}"/>
            </li>
            <li>
                <label>Repeat New Password</label>
                <input required type = "password" name = "password_again" pattern=".{6,32}"/>
            </li>
            <input type = "submit" value = "change password"/>
        </ul>
    </form>

<?php
    }
?>
<div id="controls">
    <ul>
        <a id = "changepassword" href = "#login"><li>Change Password</li></a>
        <a href = "#"><li>Edit Profile</li></a>
        <?php if (is_admin()) { ?><a href = "#admin"><li>Administrate</li></a><?php }?>
        <a href = "logout.php"><li>Log out</li></a>
        <div id = "panel"></div>
    </ul>
</div>
<div id = "panel"><?php # include_once('template/main_site/includes/widgets/changepassword.php'); ?></div>

<script>
    $('#changepassword').click(function() {
        var phpFile = 'template/main_site/includes/widgets/' + $(this).attr('id') +'.php';
        $('#panel').html('loading...').load(phpFile);
    });
</script>

$(“#更改密码”)。单击(函数(){ var phpFile='template/main_site/includes/widgets/'+$(this.attr('id')+'.php'; $('#panel').html('loading…').load(phpFile); });
如果我是个白痴,你可以骗我。我不在乎。如果是jQuery中的安全块,请告诉我。我阅读了很多load的文档,试图找出它不起作用的原因。如果我做不到,我希望这个社区告诉我,这样我就可以放弃。我真的只想要这些文件的实时包含。对我来说,可能还有另一个解决办法。如果是,请提出建议。我可以试着建造它。谢谢。


<script>
$(function() {
    $('#changepassword').click(function(e) {
        e.preventDefault();
        var phpFile = 'template/main_site/includes/widgets/' + $(this).attr('id') +'.php';
        $.get(phpFile,{},function(response) {
            $('#panel').html(response);
        });
    });
});
</script>
$(函数(){ $(“#更改密码”)。单击(函数(e){ e、 预防默认值(); var phpFile='template/main_site/includes/widgets/'+$(this.attr('id')+'.php'; $.get(phpFile,{},函数(响应){ $('#panel').html(回复); }); }); });
您需要包装脚本,以便在DOM就绪后立即执行。

您没有使用jQuery函数。DOM完全加载后,此函数将执行脚本。所以把你的整个剧本都包在里面

<script>
$(document).ready(function() {
    $('#changepassword').click(function() {
        var phpFile = 'template/main_site/includes/widgets/' + $(this).attr('id') +'.php';
        $('#panel').html('loading...').load(phpFile);
    });
});
</script>

$(文档).ready(函数(){
$(“#更改密码”)。单击(函数(){
var phpFile='template/main_site/includes/widgets/'+$(this.attr('id')+'.php';
$('#panel').html('loading…').load(phpFile);
});
});

这是
模板/main\u站点/includes/widgets/
真实路径吗?您能在浏览器中打开您试图使用jquery加载的URL吗?``尝试在事件上添加
.preventDefault()
方法。您知道,在加载它所包含的
.php
文件之前,此脚本不会加载到DOM中,对吗?确定。。还有一个更改-您需要监视控制台以查看发生了什么…听起来好像您没有从
changepassword.php
脚本中得到预期的响应。@bjames105:使用此脚本时,单击事件会得到什么结果?您是否检查了浏览器控制台?您是否在那里遇到了任何错误?使用jQuery选项卡不是一个坏主意…:)