简体   繁体   中英

Why will this page not work correctly when loaded dynamically in a div tag?

This is an adaption of a much longer question, because I pinpointed the question to be more direct without so much information. I'm using This to dynamically load pages in my div tag, but certain things stop working when loaded. Specifically some jquery stuff. The registration does not check the username ect when loaded in this div, and I can't figure out why. If code is needed to be posted I can do so, but I think it may simply lie in the way the pages are loaded, just not sure which or why. Here is the link to my test page to see what I'm talking about. Hover over login then click "register". it will load the form but it doesn't check the username with the jquery and such I have. Here is the single registration page that works just fine by itself, and this shows what I'm trying to do as well. Fiddle with javascript/jquery and html . I left some PHP in just in case it's doing something funky, and left out the css because its for the message box, and that doesn't effect this, and will still show up for tests without it.

This is the PHP that process the registration:

<?php
//have to use &_POST instead of vars for regular vars because of bug
//hash the password
$hash = hash('sha256', $_POST['pass1']);

//creates a 3 character sequence, hash pass again
function createSalt(){    
    $string = md5(uniqid(rand(), true));    
    return substr($string, 0, 3);
}
$salt = createSalt();
$hash = hash('sha256', $salt . $hash);

//check registration code
require('config/config.php');
//match the id with the registration code to update the correct row
$result = mysql_query("SELECT id FROM user WHERE regcode=
'". mysql_real_escape_string($_POST['regcode']) ."'") or die('Unable to query!');
$row = mysql_fetch_array($result);
if ($row['id'] != "") {
    $updateid = $row['id'];
} else {
    die("No matching registration code!");
}

//check if id is blank, means registration is blank
if (isset($updateid)) {
//update into database
$result = mysql_query("UPDATE user SET username='". mysql_real_escape_string($_POST['username']) ."', 
        password='". $hash ."', salt='". $salt ."', 
        email='". mysql_real_escape_string($_POST['email']) ."', 
        firstname='". mysql_real_escape_string($_POST['firstname']) ."', 
        lastname='". mysql_real_escape_string($_POST['lastname']) ."', 
        regcode='', joined=NOW(), lastlogin=NOW(), active='yes' 
        WHERE id='". $updateid ."'") or die(mysql_error());

//echo $query.",".$_POST['username'].",".$hash.",".$_POST['email'].",".$_POST['firstname'].",
//    ".$_POST['lastname'].",".$_POST['regcode'].",". $updateid ."";
//mysql_close();
echo 'yes';
} else {
echo 'noregcode'; 
}
?>

PS Please ignore outdated PHP. While it is bad, I just haven't fixed it yet and know I will have to soon.

The reason it doesn't work is that that code you're using simply does nothing to make it work. The code stuffs the response into a DOM element but doesn't try to run the scripts. A simple update to the innerHTML property of an element doesn't cause embedded scripts to be run.

You could modify that script if you want, but since you tagged this question with jQuery I would urge you in the strongest possible terms to dump that script and do this with jQuery, which (if you do it right) will do the work necessary to cause embedded scripts to be run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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