0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Thank you Naveed , but sometimes i need to pass data to the server with in URL then how to handle this ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.