简体   繁体   English

为什么在div标签中动态加载此页面时,该页面无法正常工作?

[英]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. 我正在使用This来动态加载div标签中的页面,但是某些东西在加载时会停止工作。 Specifically some jquery stuff. 特别是一些jQuery的东西。 The registration does not check the username ect when loaded in this div, and I can't figure out why. 在此div中加载时,注册不检查用户名ect,我不知道为什么。 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. 它会加载表单,但不会通过jquery来检查用户名,而我这样。 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 . 摆弄javascript / jquery和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. 我留了一些PHP,以防万一它做得很时髦,并省略了CSS,因为它用于消息框,但这并不会影响它,如果没有它,它仍然会出现在测试中。

This is the PHP that process the registration: 这是处理注册的PHP:

<?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. PS请忽略过时的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. 该代码将响应填充到DOM元素中,但不尝试运行脚本。 A simple update to the innerHTML property of an element doesn't cause embedded scripts to be run. 对元素的innerHTML属性进行简单更新不会导致运行嵌入式脚本。

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. 您可以根据需要修改该脚本,但是由于您使用jQuery标记了这个问题,因此我强烈建议您使用最强的术语来转储该脚本,并使用jQuery进行此操作(如果您做对了,它将执行必要的工作)使嵌入式脚本运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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