Spring MVC + JQuery + Ajax问题

我正在尝试使用Jquery Ajax对我的Spring MVC应用程序进行Ajax调用。 应用程序控制器工作正常,但我无法使这个Ajax测试控制器工作。 触发警报但从未对控制器进行调用。 我也尝试过使用load,get,post。 他们都没有打电话给服务器。 这让我觉得我做的事情显然是错的。 如果我将URL直接放在浏览器地址栏上,则会调用控制器。

如果有人可以指导我正确的方向或告诉我我做错了什么,我将不胜感激。

JavaScript的

     function doAjax() { alert("did it even get here?"); $.ajax({ url : "simpleRequestTest.do", method: "GET", success : function(response) { $('#show').html(response); } }); }    

Simple Test

Simple Test
...

调节器

 @RequestMapping("/simpleRequestTest") public @ResponseBody String performSimple() { return "Very Simple Test"; } 

你能检查一下是否使用了正确的路径来包含jquery-1.8.1.min.js。

我为我检查了它的工作文件代码。

我认为你在ajax调用中缺少dataType

试试这个

 function doAjax() { alert("did it even get here?"); $.ajax({ url : "simpleRequestTest.do", method: "GET", success : function(response) { $('#show').html(response); }, dataType: 'text' }); } 

只需将url : "simpleRequestTest.do",更改为url : "simpleRequestTest", method: "GET", type: "GET",

我认为该方法在jquery版本1.5和最新版本中被删除