SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX problem - plz help

    Greetings,

    this is my javascript function which handles response:
    function handleResponse()
    {
    if((http.readyState == 4)&&(http.status == 200)){
    var response = http.responseText.split('|');

    alert(response[0] ); // here it displays true or false it runs last condition instead of going in first or second condition
    if(response[0] == 'true'){
    alert("oh yes");
    }else if(response[0] == 'false'){
    alert("oh no");
    }else{
    alert("nothing");
    }
    }
    }

    when response[0] = true or false it executes last condition instead of going in first or second condition . Any idea?

    Please help!

    Thanks in advance

  2. #2
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error could be on the cheking

    hi

    the error could be on the if loop

    the value returned could be a boolean one as true or false

    but you are comparing it with the string 'true' and not the boolean value true.

    That could be the cause

    try

    if(response[0] == true){
    alert("oh yes");
    }else if(response[0] == false){
    ....
    ...
    ....
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  3. #3
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no it's string i.e "true"

    Response is echoed:

    echo "true"; //PHP

  4. #4
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    try === instead of ==

    hi

    Try using === instead of ==, i think it will work
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  5. #5
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could that be parameter on your response function?

    Code:
    function handleResponse(http)
    {
    I cannot find the reference to http


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •