Spring MVC + JQuery + Ajax问题 [英] Spring MVC + JQuery + Ajax Issue

查看:96
本文介绍了Spring MVC + JQuery + Ajax问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to make an Ajax call to my Spring MVC app using a Jquery Ajax. The app controllers are working fine but I can't get this Ajax test controller to work. The alert is triggered but the call to the controller is never made. I've also tried using load, get, post. None of them call the server. Which makes me think I'm doing something obviously wrong. If I put the URL directly on the browser address bar, the controller is called.

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

If someone can guide me in the right direction or tell me what I'm doing wrong, I'd be grateful.

JavaScript

<html>
<head>
<script type="text/javascript" src="jquery-1.8.1.min.js"> </script>
<script type="text/javascript">
    function doAjax() {
        alert("did it even get here?");
        $.ajax({
            url : "simpleRequestTest.do",
            method: "GET",          
            success : function(response) {
                $('#show').html(response);
            }
        });
    }
</script>
</head>
<body>
    <h1>Simple Test </h1>
    <a href="javascript:doAjax();"> Simple Test </a>
    <br />
    <div id="show">...</div>
</body>
</html>

控制器

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

推荐答案

是否可以检查是否使用正确的路径来包含jquery-1.8.1.min.js.

Can you check whether you use correct path for include the jquery-1.8.1.min.js.

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

I checked the code it's working file for me.

这篇关于Spring MVC + JQuery + Ajax问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆