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页面加载到主页面上的div中。所有元素(表单/ javascript等)在加载的页面中都能正常工作。唯一的问题是,一旦php脚本返回ajax响应,我就无法让它显示在div上。
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.
当我单独运行signup.php页面时会显示响应,但是当它被加载到另一个页面时则不会显示。我正在使用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. 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页面的ajax调用替换load()函数,然后设置将ajax的html响应放入我想要的div中 - 效果是一样的。我得到html,因为我想要它,但跨度不会更新来自signup.php页面的ajax错误。有没有人在div中加载页面有任何澄清 - 这不是不是吗?我知道load()在放入新内容之前剥离了标签 - 但我想只要整个页面加载那么它应该不是问题 - 任何想法?请等一下!这让我疯了!
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!
求助:找到答案:当signup.php被加载到索引页面时,有两个具有相同id的跨度,因此浏览器变得混乱而没有做任何事情。这就解释了为什么它也可以单独作为一个浏览器运行,并且仍会触发所有控制台/警报 - 感谢您输入的人!
1 个解决方案
#1
0
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. I have modeled all of that without issue.
问题不在于load()或在div中加载页面。我已经毫无问题地模仿了所有这些。
Without seeing all of your ajax code, it is tough to tell what is happening. Regarding this:
如果没有看到你的所有ajax代码,很难说出发生了什么。关于这个:
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? Are you able to set the status to anything inside or outside this function?
是警报和console.log解雇?您是否可以将状态设置为此功能内部或外部的任何内容?
#1
0
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. I have modeled all of that without issue.
问题不在于load()或在div中加载页面。我已经毫无问题地模仿了所有这些。
Without seeing all of your ajax code, it is tough to tell what is happening. Regarding this:
如果没有看到你的所有ajax代码,很难说出发生了什么。关于这个:
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? Are you able to set the status to anything inside or outside this function?
是警报和console.log解雇?您是否可以将状态设置为此功能内部或外部的任何内容?