javascript - jQuery .load() function not working on my php file -
my particular situation using jquery .load() function include page site after clicking link. have chosen write code inline. have user control panel several buttons link pages edit information. have 1 password , 1 settings. i'm trying 1 work , write each loop apply more links click. php file looks this:
<?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 $key=>$value) { if (empty($value) && in_array($key, $required_fields) === true) { $errors[] = 'fields lighted red required.'; break 1; } } if (encryptbetter($_post['current_password']) === $user_data['password']) { if (trim($_post['password']) !== trim($_post['password_again'])) { $errors[] = 'your new passwords not match'; } if (strlen($_post['password']) < 6 || strlen($_post['password']) >= 32) { $errors[] = 'your new password must less 32 characters , more 6 characters.'; } } else { $errors[] = 'your current password 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 password 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 } ?>
i have php file included in containing page. note if include changepassword.php page using php include, load properly. want same thing php's include, except jquery load.
my logged in included php file looks this:
<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>
if i'm being idiot, can troll me. don't care. if it's security block in jquery, let me know. read documentation load lot of times try find out why doesn't work. if can't it, want community tell me can give up. want live include of these files. there solution me. if so, suggest it. can try build it. thank you.
<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>
you'll need wrap script can executed dom ready.
Comments
Post a Comment