0

I'm trying to use Ajax to communicate with a servlet. When i look at the Net tab in firebug, i can see that i get the right response from the server. Despite of that, the Ajaxrequest doesn't seem to be calling my vulAan function. To check if the ajaxrequest calls any function i added window.alert() functions. Only window.alert("request verstuurd") gets called. This is the code:

window.onload = function() {
    $("registreerform").observe("submit", controleer);
    $$("input")[1].observe("blur", getVulAan);
    $$("input")[2].observe("blur", getVulAan);
};

function getVulAan(event){

     var post = $$("input")[1].value;
     var huis = $$("input")[2].value;
     if (post && huis) {
     window.alert("request verstuurd");
     event.stop();
     new Ajax.Request (
      "http://www.ntwpracticumnet.ou.nl:8080/registratie/PostcodeServlet",
        { method: "get",
        parameters: {postcode: "1076CT", huisnr: "390"},
        onSucces: vulAan,
        onFailure: nietGelukt,
        onExcepton: nietGelukt
        }
      );
    }
    }
function vulAan(ajax) {
    window.alert("request geaccepteerd");
    var jsWaarde = JSON.parse(ajax.responseText);
    var plaats = jsWaarde.plaats;
    var straat = jsWaarde.straat;
    $$("input")[3].value = plaats;
    $$("input")[4].value = straat;
    }
function nietGelukt () {
    window.alert("niet gelukt");
    }

Anyone knows whats wrong?

1 Answer 1

1

You need to rename onSucces to onSuccess, check http://prototypejs.org/doc/latest/ajax/Ajax/Request/

Sign up to request clarification or add additional context in comments.

3 Comments

Your edit is wrong. You cannot replace the event with vulAan() - it will likely pass the response anyway!
It all works now. It was just a small typing error as Raunak pointed out.
@user3166227 glad it helped, sometime small mistake gets unnoticed.. Please accept answer if its fine with you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.