SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Ajax open command

    Hi!
    I am trying to call a php page using AJAX and it fails. I tested this by writing
    if(ajaxRequest.open("GET", "page.php?q="+s, true) alert("Success
    ") ;
    else alert("fail");
    and I got the fail messege.
    I am not an expert in AJAX, php is more my thing and was wondering if any of the brilliant people here will be able to find out what the problem is.
    the PHP code works fine, i tested it regardless of the AJAX.

    the code is as follows:


    function validateZip(zip) {
    if(zip == "ZIP CODE" || zip == "")
    {
    alert("Please insert a zip code");
    }
    zipCurrent=zip;
    var ajaxRequest;
    try {
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
    } catch (e) {
    // Internet Explorer Browsers
    try {
    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
    // Something went wrong
    alert("Your browser broke!");
    return false;
    }
    }
    }

    ajaxRequest.onreadystatechange = function () {
    var resp;
    if (ajaxRequest.readyState == 4&&ajaxRequest.status==200) {
    resp = ajaxRequest.responseText;
    if (resp == "1") {
    $("#ziperr").html("1");
    } else {
    $("#ziperr").html("0");
    }

    zipCurrent = resp;

    }

    }


    ajaxRequest.open("GET", "checkzipPnina.php?q="+zip, true);
    ajaxRequest.send(null);
    return;

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would use the JQuery library and do it this way:

    $.get('checkzipPnina.php?q=' + zip, function(data) {
    alert (data);
    });

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Figured it out.....
    Apparantly the JS was skipping the AJAX, when I set the lthird parameter in the AJAX open command it worked!


Tags for this Thread

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
  •