Javascript的响应从加载网页没有显示与<跨度>虽然我可以看到它在Firebug可以看到、跨度、它在、加载

2023-09-10 17:50:57 作者:你的眼睛会笑

我加载一个signup.php页面到我的主网页股利。所有的元素(表格/ javascript等等)都工作正常,在加载页面。唯一的问题是,一旦PHP脚本返回Ajax响应我不能让它显示出来的股利。

I'm loading a signup.php page into a div on my main page. All of the elements (forms/javascript etc) are working fine in the loaded page. The only issue is that once the php script returns the ajax response I cannot get it to show up on the div.

的反应表明,当我运行signup.php页独立的,而不是在它被加载到另一页。我使用load()函数来进行负载 - 我知道,负载()条标记等,但不是当你加载整个页面,这是我在做什么,所以我推测它应该工作。

The response shows up when I run the signup.php page standalone, but not when it is loaded into another page. I'm using the load() function to carry out the load - I know that load() strips tags etc but not when you load the whole page, which is what I am doing so I figure it should work.

我还检查了回应文中通过从即使在主网页上加载的PHP脚本来 - 我只是不能得到它显示在跨度。

I have checked that the response text does come through from the PHP script even when loaded on the main page - I just cant get it to show up in the span.

下面是JavaScript code为正在加载的注册页面(signup.php)(还没有包括在PHP作为其工作):

Here is the javascript code for the signup page (signup.php) being loaded (havent included the php as its working):

function signup(){
var e = _("email").value;
var p1 = _("pass1").value;
var p2 = _("pass2").value;
var status = _("status");
if( e == "" || p1 == "" || p2 == ""){
    status.innerHTML = "Fill out all of the form data";
    console.log(status.innerHTML);
} else if(p1 != p2){
    status.innerHTML = "Your password fields do not match";
} else {
    status.innerHTML = 'please wait ...';
    var ajax = ajaxObj("POST", "signup.php");
    ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
            if(ajax.responseText != "OK"){
            alert(ajax.responseText);
            console.log(ajax.responseText);
                status.innerHTML = ajax.responseText;
                _("signupbtn").style.display = "block";
            } else {
            console.log(ajax.status);
                console.log(ajax.responseText);

                _("p1").innerHTML = "Please check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
            }
        }
    }
    ajax.send("e="+e+"&p="+p1);
}

和HTML表单:

         <form name="signupform" id="signupform" onsubmit="return false;">

      <div>Email Address:</div>
    <input id="email" type="text" class="searchbox" onfocus="emptyElement('status')" onkeyup="restrict('email')" maxlength="88">
    <div>Create Password:</div>
    <input id="pass1" type="password" class="searchbox" onfocus="emptyElement('status')" maxlength="16">
    <div>Confirm Password:</div>
    <input id="pass2" type="password" class="searchbox" onfocus="emptyElement('status')" maxlength="16">
      </form>           
    <br> <a href="#" alt="Signup" onclick="signup()">Create Account</a><p>
<span id="status" class="statuserror">This is where i want the response to show</span>

和Jquery的被用来加载上面到#container的格主网页(的index.php)上:

and the Jquery being used to load the above into the #container div on the main page (index.php):

function becometutor(){
$('#container').slideUp(200);
$('#searchBar').slideUp(200);
setTimeout(function(){
$('#container').load("signup.php")}, 200);

$('#container').slideDown(200);
}

编辑:好男人 - 这样一个更新:我试着用Ajax调用的signup.php页面替换load()函数,然后设置把AJAX的HTML响应到哪里​​我想它的股利 - 效果是相同的。我得到的HTML我所想要的,但跨度不从signup.php页面阿贾克斯错误更新。有没有人有内格的页面加载任何澄清 - 这是一种没有没有?我知道,load()的剥离将在新的内容之前的标签 - 但我认为,只要整个页面加载,然后它不应该是一个问题 - 任何想法?请请请!它是我发疯!

OK guys - so an update: I tried replacing the load()function with an ajax call for the signup.php page and then setting putting the html response of the ajax into the div where I want it - the effect is the same. I get the html as i want it but the span does not update with the ajax errors from the signup.php page. Does anyone have any clarification on loading pages within div - is this a no no? I know that load() strips tags before putting in the new content - but I thought so long as the whole page is loading then it should not be a problem - any ideas? PLEASE PLEASE PLEASE!It's driving me nuts!

解决:找到了答案:当signup.php加载到索引页,有两个跨度具有相同的ID,这样在浏览器感到困惑,并没有做任何事情。这就解释了为什么它可以作为独立的过于单一的浏览器也是如此,仍然激发所有的控制台/警报 - !感谢您输入家伙

SOLVED: Found the answer: when signup.php is loaded into the index page, there are two spans with the same id so the browser is getting confused and not doing anything. This explains why it works as standalone too a single browser too, and still fires all the console/alerts - Thanks for your input guys!

推荐答案

我会评论这一点,但很可惜我代表不够高,所以我要提出一个答案。

I would have commented this, but alas my rep is not high enough, so I have to submit an answer.

这个问题是不是与负载(),或在一个div加载页面。我曾经模仿了这一切没有问题。

The issue is not with load() or loading a page in a div. I have modeled all of that without issue.

在没有看到所有的AJAX code,这是很难知道发生了什么。关于这一点:

Without seeing all of your ajax code, it is tough to tell what is happening. Regarding this:

ajax.onreadystatechange = function() {
    if(ajaxReturn(ajax) == true) {
        if(ajax.responseText != "OK"){
        alert(ajax.responseText);
        console.log(ajax.responseText);
            status.innerHTML = ajax.responseText;
            _("signupbtn").style.display = "block";
        }

是警惕和的console.log射击?您可以设置内部或此功能?

are the alert and console.log firing? Are you able to set the status to anything inside or outside this function?