Reputation:
I have one JSP File and one JS File . So inside my JSP File , i have included the JS (Javascript File) like this
<script type="text/javascript" src="HumbleFinance.js"></script>
As part of my JSP i have Inside JSP File , I have
jQuery.ajax({
url: '/HumblFin/Serv',
type: 'GET',
contentType: 'application/json',
dataType: 'json',
timeout: 5000,
success: function(data) {
drawChart(data);
}
Now my question is , From the included JS File , how can i make a call to the jQuery.ajax( function ?? which has been defined in JSP File ??
Please advice
Upvotes: 0
Views: 13622
Reputation: 3175
The same way you added the ajax call. It can be something like this:
function callAjax(data){
jQuery.ajax({
url: '/HumblFin/Serv',
type: 'GET',
contentType: 'application/json',
data: data,
dataType: 'json',
timeout: 5000,
success: function(data) {
drawChart(data);
}
}
Now you can call the function callAjax()
anywhere you want. Obviously inside a javascript file or <script type="text/javascript">callAjax();</script>
if you're using inline javascript. PS> I've added data as a parameter. Now you can pass the data to the function and it will be passed to the server through ajax call.
Upvotes: 0
Reputation: 944546
Just call it. The only requirement is the the <script>
element that loads the functions you want must be loaded into the document before you try to call those function.
Upvotes: 1