最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Making an AJAX call from included JavaScript File? - Stack Overflow

programmeradmin2浏览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

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

Share Improve this question edited Apr 19, 2011 at 9:26 Quentin 945k133 gold badges1.3k silver badges1.4k bronze badges asked Apr 19, 2011 at 9:22 user663724user663724
Add a ment  | 

2 Answers 2

Reset to default 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.

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.

发布评论

评论列表(0)

  1. 暂无评论