PHP interaction with AJAX -


so have function in javascript file:

function updatethiscoursehistory(){     var ajax= new ajax.request("runneededqueries.php",             {                 method: "post",                 parameters: {database: "history", action:"update"},                 onsuccess: function(){alert("this course history entry has been updated");},                 onfailure: function(){alert("could not find entry specified primary key");}                     }     ); } 

suppose php file

<?php header('http/1.0 400 bad request');  ?> 

would make onfailure method execute?

the onsuccess callback fire when php script responds http 2xx response code , onfailure callback fire if http error code returned. if want take action based on response value, have options:

  • modify php script return http error response (perhaps 400) on failure , take action based on specific value returned.
    • header('http/1.0 400 bad request');
  • update ajax handler inspect data returned , take action based on content.
    • onsuccess: function(transport){ if transport.responsetext == 'expected value' ...}

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -