简体   繁体   中英

Uncaught ReferenceError: myfunction is not defined in javascript and jquery

I am trying to pass some values through function in onclick event written in button , then in function i want to pass these values through ajax and print the output in the same page . i have applied some logic but getting an error . how can i do the required task

Edited

 <script>
  function myfunction(nm,em,mob,id){

   $.ajax({
  url: "<?php echo ABSPATH.'wp-content/plugins/testwp/submit.php' ;?>",
  type: "post",
  data: { nm:nm , em:em , mob:mob , id:id }
  }).done(function(obj){
  $('#resu').html(obj);
  ('.fade').hide();
  });

 }
 </script>



     <button type="submit" class="btn btn-default" onclick="return myfunction('<?php echo $re->name;?>','<?php echo $re->email;?>','<?php echo $re->mob;?>','<?php echo $re->id;?>');">Submit</button>

Try this:

There is no need of $(document).ready

 function myfunction(nm, em, mob, id) { alert('Your ajax call will go here !') } 
 <button type="submit" class="btn btn-default" onclick="return myfunction(1,2,3,4);">Submit</button> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM