I am using JavaScript and jQuery. My main file has My.js
and Ajax.
function build_one(){
alert("inside build_one");
}
<script type="text/javascript">
..
// Here I want to make call function defined in My.js build_one()
..
// Here is the Ajax call
$.ajax({
type:'POST',
url: 'ajax.php',
data:'id='+id ,
success: function(data){
$("#response").html(data);
}
});
...
</script>
How do I make the build_one() function call before the Ajax function?
This should work:
<script type="text/javascript" src="My.js"></script>
<script type="text/javascript">
build_one();
$.ajax({
type:'POST',
url: 'ajax.php',
data:'id='+id ,
success: function(data){
$("#response").html(data);
}
});
</script>
First you have to import your file before calling the function using the following
<script type="text/javascript" src="My.js"></script>
Now you can call your function where ever you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With