Search code examples
javascriptajaxformssubmitmootools

Mootools ajax form response


I'm trying to send a form with mootools and depending on the response from the php script do such or such thing. The thing is I fail to be able to use conditional statements inside of the onComplete part of the code.

I'm missing something really obvious probably, please help me :)

$('formName').addEvent('submit', function(e){
    e.stop();                      
    var req = new Request.HTML({
      url       : 'phpUrl.php',
      data      : $('formName'),
      update    : $('modify-me'),
      onComplete: function(){
            $('formName').reset();
            if($('modify-me').get('text') = "1"){
                alert("succeed");
                }else{
                alert("failure");
                }
            }  
    }).send();                    
  });

This was my lame attempt to use the php response in the code, but of course it didn't work. Needless to say I'm new to all this asynchronous client-server communication stuff, but I'm really intrigued by it.


Solution

  • You are assigning in your if statement (single =), not checking equality (==). Change the line

    if($('modify-me').get('text') = "1")
    

    to

    if($('modify-me').get('text') == "1")