admin管理员组文章数量:1427995
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 user663724user6637242 Answers
Reset to default 1Just 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.
本文标签: jqueryMaking an AJAX call from included JavaScript FileStack Overflow
版权声明:本文标题:jquery - Making an AJAX call from included JavaScript File? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745510341a2661439.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论