I am using jQuery and JavaScript, I need to call the jQuery function inside my JavaScript code.
My jQuery code:
function display(id){ $.ajax({ type:'POST', url: 'ajax.php', data:'id='+id , success: function(data){ $('#response').html(data); }//success }); //Ajax //Here I need to return the ajax.php salary //return ? }
My ajax.php file has:
<?php session_start(); .... echo '$salary'; ?>
My JavaScript function has:
my.js function showName(){ var id = 12; var a = display(id); //Here I need to call the jQuery function display(). }
How do I call the jQuery function inside JavaScript code and how do I return the PHP values to jQuery?
I really think you need to separate both things:
Like:
Then in your my.js code:
Remember that display() will trigger your Ajax call and the code will continue, then when you get your response (maybe some seconds or ms later) anotherFunction() will be called. That’s why Ajax is asynchronous. If you need synchronous calls, check the documentation about jQuery and Ajax technique.