Forums

How to call ajax on form load

komal2887 15 Sep, 2017
I want to called one API on form load, I added this js code onLoad>

jQuery(document).ready(function ($) {
  alert('ready');
   $.ajax({
    type:'POST',
    url: '<?php echo JURI::base();?>baseapi.php',
    data: {firstname:firstname}, 
    cache:false,
    processData: false,                  
    success:function(data){
      alert(data);
      console.log(data);
    }
  });
});


I got alert message 'ready' but after that nothing is happens in my network.
GreyHead 15 Sep, 2017
Hi komal2887,

Is the PHP snippet being executed - do you see the correct JavaScript in the page source? If not you may need to use a Custom Code element to set that as a JavaSCript variable and alter your script to add it to the URL.

Bob
This topic is locked and no more replies can be posted.