Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:28:11+00:00 2026-06-04T23:28:11+00:00

Okay, so I’ve tried pretty much everything. $.post(include/ajax.php, { type: workbookNumber, wbn: $(input[name=’wbn’]).val() },

  • 0

Okay, so I’ve tried pretty much everything.

$.post("include/ajax.php", { type: "workbookNumber", wbn: $("input[name='wbn']").val() }, function(data) {
    error.push("<li>"+data+"</li>");
    alert(data);
});

The error.push is the error array that’s been created, it works perfectly but it does not add to the array at all. It’s as if that line of code does not exist. There have been instances in the comma variable data where there is an extra comma, showing it is there but even so, the <li></li> should still show.

jQuery.ajax({
    type: "POST",
    url: "include/ajax.php",
    dataType:"html",
    data: { type: "workbookNumber", wbn: $("input[name='wbn']").val() },
    success:function(response) {
    alert(response);
    },
    error:function (xhr, ajaxOptions, thrownError) {
        alert("damn. -_-");
        alert(xhr.status);
        alert(thrownError);
    }    
});

I can’t think of any reasonable explanation for this, I was thinking that the PHP doesn’t have enough time to show the result as it’s searching through a database of over 20000 codes however, the result still comes back through the alert, just not through the error array in actual text that can be shown on screen.

The error array works fine, it’s just this function that doesn’t work. Here’s some other examples of what DOES work correctly:

if($("input[name='fname']").val() == "") {
    error.push("<li>The first name field is blank</li>");
}
if($("input[name='lname']").val() == "") {
    error.push("<li>The last name field is blank</li>");
}

if($("select[name='usertype']").val() == 0) {
    if($("input[name='vcode']").val() == "") {
        error.push("<li>The voucher code field is blank</li>");
    } else {
        $.post("include/ajax.php", { type: "findVoucher", vcode: $("input[name='vcode']").val() }, function(data) {
            if(data == "none") {
                error.push("<li>The voucher code does not exist</li>");
            }
        });
    }
}

Here’s the whole code:

$(document).ready(function() {
$("#sit_date").datepicker();
$("select[name='usertype']").change(function() {
    if($(this).val()=="0") {
        $(".indv").slideUp(500);
        $(".comp").slideDown(500);
    } else {
        $(".indv").slideDown(500);
        $(".comp").slideUp(500);
    }
});
$("input[name='marka'],input[name='markb']").bind("keypress paste keyup  blur focus", function() {
    var marka = $("input[name='marka']").val();
    var markb = $("input[name='markb']").val();
    var perc = (marka/markb)*100;
    if(perc>0 && perc<=100) {
        $("#per").html(Math.round(perc));
    } else {
        $("#per").html("");
    }
});
$("input[name='vcode']").bind("keypress keyup paste blur focus", function() {
    $.post("include/ajax.php", { type: "checkVoucher", vcode: $(this).val() }, function(data) {
        $("input[name='group']").val(data);
    });
    $.post("include/ajax.php", { type: "checkType", vcode: $(this).val() }, function(data) {
        $("input[name='certificates']").val(data);
    });
});

$("input[name='wbn']").bind("keypress keyup paste blur focus", function() {
    $.post("include/ajax.php", { type: "getAssessment", wbn: $(this).val() }, function(data) {
        if(data!="") {
            $("select[name='assessment']").html(data);
        }
    });
});

/*
//turn into function
$(document).keyup(function(event){
    if(event.keyCode == 13){
        alert("works");
        $("input[name='manual_add']").click();
    }
});
*/

var error = [];
$("input[name='manual_add']").click(function() {
    if($("input[name='fname']").val() == "") {
        error.push("<li>The first name field is blank</li>");
    }
    if($("input[name='lname']").val() == "") {
        error.push("<li>The last name field is blank</li>");
    }

    if($("select[name='usertype']").val() == 0) {
        if($("input[name='vcode']").val() == "") {
            error.push("<li>The voucher code field is blank</li>");
        } else {
            $.post("include/ajax.php", { type: "findVoucher", vcode: $("input[name='vcode']").val() }, function(data) {
                if(data == "none") {
                    error.push("<li>The voucher code does not exist</li>");
                }
            });
        }
    }

    if($("input[name='wbn']").val() == "") {
        error.push("<li>The workbook number field is blank</li>");
    } else {

        $.post("include/ajax.php", { type: "workbookNumber", wbn: $("input[name='wbn']").val() }, function(data) {
            error.push("<li>"+data+"</li>");
            //this is the only thing that works correctly:
            alert(data);
        });

    }

    if(($("input[name='questions']").val() == "") && ($("input[name='marka']").val() != $("input[name='markb']").val())) {
        error.push("<li>The questions wrong field is blank</li>");
    }

    var list = "";
    $.each(error, function(i,val) { 
        list += val;
    }); 

    if(error.length>0) {
        $(".error").slideUp(500);
        $(".jquery-error ul").html("").append(list);
        $(".jquery-error").slideDown(500);
    } else {
        $("form").submit();
    }
});
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:28:13+00:00Added an answer on June 4, 2026 at 11:28 pm

    The var error is declared in your click() function and is thus not accessible outside that function. Declare it globally and your code should work. (Worked fine for me on jsfiddle with a global error variable.)

    The rest of your error handling code works fine, because it is defined in the same scope as your error variable (the click() function). But the callback to your ajax request is not executed in the context of your function, but in the window context. This is definitely a scope issue.

    Of course you have to wait for the response from the server to come back to update your error notifications. Write a function that iterates over the error array and displays the corresponding notifications and then call that function from the error function of your AJAX call.

    Try the following:

    var error = [];
    
    jQuery.ajax({
        type: "POST",
        url: "include/ajax.php",
        dataType:"html",
        data: { type: "workbookNumber", wbn: $("input[name='wbn']").val() },
        success:function(response) {
            alert(response);
        },
        error:function (xhr, ajaxOptions, thrownError) {
            error.push("<li>"+thrownError+"</li>");
            showErrors();
        }    
    });​
    
    function showErrors () {
         var list = "";
        $.each(error, function(i,val) { 
            list += val;
        }); 
    
        if(error.length>0) {
            $(".error").slideUp(500);
            $(".jquery-error ul").html("").append(list);
            $(".jquery-error").slideDown(500);
        } else {
            $("form").submit();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so I have a simple HTML Input fragment: <input id=txtFirstName type=text class=txtBox runat=server
Okay, so here's my problem: We use FOP for creating pretty report output. We
Okay so my question is this. Say I have a simple C++ code: #include
Okay, this one is pretty obvious to everyone who use Django and frequently asked
Okay, here's the rundown. I'm developing a video hosting site with PHP and jQuery
Okay, so I'm not even sure how to ask this question (much less search
OKay, this is probably pretty noob, but I couldn't find how to solve it.
Okay, so I've tried to use sort to vector of items so the size
Okay, I've looked all over the internet for a good solution to get PHP
Okay so im working on this php image upload system but for some reason

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.