项目计数返回0,而预期返回1
I always will be send to to the else
.
I have the page functions.php
with all my functions we are now looking at the function registerNewAcc()
:
<?
function registerNewAcc()
{
return false;
}
?>
Then i got the page registerHandler.php
where im checking if the function registerNewAcc() == false
:
<?
if (registerNewAcc() == false)
{
echo '<div class="invisible"></div>';
echo 'fout';
}
else
{
echo 'You are register succesfull!<br>Check your e-mail, we have send you an e-mail with a verification-link in it to verify your account.';
}
?>
And in my form.js
file I find the class .invisible
:
<script type="text/javascript">
var registerStatus = $(data).find(".invisible");
if (registerStatus.length >= 1) {
//Kijkt of er regisratie fout is
$("div.statusBalk").hide().slideDown().css("display", "block").css("background-color", "red").empty().append(data);
$("span.inputCheck").empty();
$inputs.prop("disabled", false);
} else {
//Kijkt of er regisratie fout is
$("div.statusBalk").hide().slideDown().css("display", "block").css("background-color", "green").empty().append(data);
$("span.inputCheck").empty();
$inputs.prop("disabled", false);
}
</script>
But its always go to the else
of the js script.
He always display 0 elements found.
I alerted it and it display 0
[ADDED]
<script type="text/javascript">
$( "form#registerForm" ).submit(function( event ) {
// Stop form from submitting normally
event.preventDefault();
var $form = $(this);
var $url = "registerHandler.php?action=registerCheck";
var $inputs = $form.find("input");
var posting = $.post($url, $form.serialize());
$inputs.prop("disabled", true);
posting.done(function (data) {
var formStatus = $(data).find(".inputCheckCross");
if (formStatus.length >= 1) {
//Wanneer het formulier fout is
$("div.registerError").hide().fadeIn().css("display", "block").empty().append(data);
$("div.statusBalk").css("display", "none");
$("span.inputCheck").empty();
$inputs.prop("disabled", false);
} else {
var registerStatus = data.find(".invisible");
if (registerStatus.length >= 1) {
//Kijkt of er regisratie fout is
$("div.statusBalk").hide().slideDown().css("display", "block").css("background-color", "red").empty().append(data);
$("span.inputCheck").empty();
$inputs.prop("disabled", false);
} else {
//Kijkt of er regisratie fout is
$("div.statusBalk").hide().slideDown().css("display", "block").css("background-color", "green").empty().append(data);
$("span.inputCheck").empty();
$inputs.prop("disabled", false);
}
}
});
});
</script>
This is the whole js part of what i check.
Found the thing, it is weard but it works now.
I had to change the line:
//From
if (registerStatus.length >= 1) {
//To
if (registerStatus) {
I think its weard because I do this also earlyer on the same way on the line with the data:
$(formStatus.length >= 1) {
And there it is working.
I think i have a idea why it didn't work but im not sure.
The count elements of .invisible is 1 and its always 1 there are not more of it.
So maybe that is the thing?
Hope you guys have on this a suggestion, leave it in the comments please.
I'm unsure what you're trying to accomplish with $(data).find(".invisable")
. Seems like an incorrect selector to me. Try using $(".invisable").length
instead.
It seems like the misspelling of "invisible" in some places in the code may be your problem.
correct: invisible
incorrect: invisable
There is something I found,
when I click for the first time on the submit button it shows the green bar
when I click for the second time on the submit button it shows the red bar.
Still dont know what the problem can be :s
Hope this can help.