简体   繁体   English

<span>虽然我可以在firebug中看到它,但</span>加载页面的Javascript响应没有显示出来

[英]Javascript response from a loaded page is not showing up in <span> although i can see it in firebug

I'm loading a signup.php page into a div on my main page. 我正在将signup.php页面加载到主页面上的div中。 All of the elements (forms/javascript etc) are working fine in the loaded page. 所有元素(表单/ javascript等)在加载的页面中都能正常工作。 The only issue is that once the php script returns the ajax response I cannot get it to show up on the div. 唯一的问题是,一旦php脚本返回ajax响应,我就无法让它显示在div上。

The response shows up when I run the signup.php page standalone, but not when it is loaded into another page. 当我单独运行signup.php页面时会显示响应,但是当它被加载到另一个页面时则不会显示。 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. 我正在使用load()函数来执行加载 - 我知道load()剥离了标签等,但是在加载整个页面时却没有,这就是我正在做的事情,所以我觉得它应该可以工作。

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. 我已经检查过,即使加载到主页面上,响应文本也会从PHP脚本中传来 - 我只是不能让它显示在跨度中。

Here is the javascript code for the signup page (signup.php) being loaded (havent included the php as its working): 这是正在加载的注册页面(signup.php)的javascript代码(还没有包含php作为其工作):

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);
}

And the HTML form: 和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>

and the Jquery being used to load the above into the #container div on the main page (index.php): 和Jquery用于将上面的内容加载到主页面上的#container div(index.php):

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

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

EDIT: 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. 编辑:好人 - 所以更新:我尝试用signup.php页面的ajax调用替换load()函数,然后设置将ajax的html响应放入我想要的div中 - 效果是一样的。 I get the html as i want it but the span does not update with the ajax errors from the signup.php page. 我得到了html,因为我想要它,但是span不会更新来自signup.php页面的ajax错误。 Does anyone have any clarification on loading pages within div - is this a no no? 有没有人在div中加载页面有任何澄清 - 这是不是不是吗? 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? 我知道load()在放入新内容之前剥离标签 - 但我想只要整个页面加载那么它应该不是问题 - 任何想法? PLEASE PLEASE PLEASE!It's driving me nuts! 请等一下!这让我疯了!

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. 求助:找到答案:当signup.php被加载到索引页面时,有两个具有相同id的跨度,因此浏览器变得混乱而没有做任何事情。 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. 我会评论这个,但是我的代表不够高,所以我必须提交一个答案。

The issue is not with load() or loading a page in a div. 问题不在于load()或在div中加载页面。 I have modeled all of that without issue. 我已经毫无问题地模仿了所有这些。

Without seeing all of your ajax code, it is tough to tell what is happening. 如果没有看到你所有的ajax代码,就很难分辨出发生了什么。 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";
        }

are the alert and console.log firing? 是警报和console.log解雇? Are you able to set the status to anything inside or outside this function? 您是否可以将状态设置为此功能内部或外部的任何内容?

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

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