473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

JavaScript Method to call Spring MVC controller method through ajax

I would like to call spring mvc method when ever onUnload.
So i write the code

in <body onUnload="bye()"></body>
In javascript
-------------
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.             function bye(){
  3.                 alert("Before Ajax..!");
  4.                 $.ajax({  
  5.                     type : 'GET',  
  6.                     url : "/patient/myMealPlan",  
  7.  
  8.                 });
  9.                 alert("onUnLoad Bye");
  10.             }
  11.         </script>

In spring MVC Controller class
--------------------------------
Expand|Select|Wrap|Line Numbers
  1. @RequestMapping(value="myMealPlan", method=RequestMethod.GET)
  2.     public String init(ModelMap map, HttpServletRequest request){
  3.     System.out.println("Bye method called..!");
In java-script alert()'s are calling properly but coming to spring MVC controller will not call.
Why it is not called ?
Is there any .js file we need to import in .jsp file ?
if so which file .js file i would like to import?
Apr 19 '13 #1
1 22047
Dormilich
8,658 Expert Mod 8TB
Is there any .js file we need to import in .jsp file ?
if so which file .js file i would like to import?
JavaScript runs on the client as Spring runs on the server … so you don’t need to load any JS into Spring (I even doubt Spring could do something useful with a JS file).

hm, and since you call the JS function on unload, how should you see the server response?
Apr 20 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: psimakov | last post by:
There is a new article out by Pavel Simakov entitled: Javascript Refactoring for safer, faster, better AJAX. ...
1
by: Victor Jones | last post by:
I was involved recently in desiging a middle tier class where we essentially need not track the state of the object, hence a class with static methods was preferred. But there were some debate as...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
4
by: Rob Shorney | last post by:
Hi, I am using .Net 2003 , c# asp.net. The situation i have is this. I have a asp.net page which in the codebehind maintains an xml document in memory. The user can click on a button to popup a...
2
by: mhust6 | last post by:
I am trying to call a java method from within my Javascript, but cannot seem to get it to work. All the examples I have found online and in the forums are using Java applets. I have a method that...
0
by: Bhaskardeep Khaund | last post by:
Hi, I have a page which have a public method. From that page, a pop-up window opens and after some action, I want to call the public method of the parent window, from the popup window. I know...
0
by: vksundari | last post by:
how to call a ASP.Net User defined method or built in method from java cript function
4
by: faraz | last post by:
I have a javascript function that i want to call masterpage load method called. I cant add onLoad event of body or table in master page. I have put the call to script function in <form>, it...
0
by: iaminlost | last post by:
for example. in python : def MyMethod(self): print "MyMethod" window.external.Mythod() i want this javascript language can call the python method, what else should i do?
13
by: Gouri.Mahajan7 | last post by:
Hello, Can anybody please tell me how to trap the browser close event. when that is fired I want to call the web method. Thanks in advance. Regards, Gouri.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.