Ajax调用不同的控制器 [英] Ajax call to different controller

查看:81
本文介绍了Ajax调用不同的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图从与该控制器无关的jsp页面调用另一个控制器. 我要执行的操作:页面加载后,我从控制器A加载了jsp,我想在不更改页面位置的情况下调用控制器B.

I have been trying to call a different controller from a jsp page that is not associated with that controller. What I'm trying to do: The jsp loads from controller A, after the page loads I want to then call Controller B without changing the page location.

我尝试了很多事情,但还没有成功.

I've tried a number of things and have yet to be successful.

Ajax尝试:

$(window).load(function () {
    var url = $('#analyticLog').attr('href');

    $.ajax({
        type: "POST",
        url: url,
        success: function(html)
        {
                $("#analyticLogAjax").replaceWith($("#analyticLogAjax",$(html)));
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
          }
    });
});

window.location尝试:

window.location try:

$(window).load(function () {
        window.location = $('#analyticLog').attr('href');

});

在每个引用中都有一个锚点,该锚点指向控制器要映射到的动作. Ive还与视图控制器一起玩,该控制器处理我们的操作请求和映射,希望使空视图不引用新的视图".但是接着我的500张支票被抓住了,那就是通行证.

There is an anchor being referenced in each that points to the action from which the controller is mapped to. Ive also played with the view controller that handles our action requests and mappings hoping to enable null views to not reference a new 'view'. But then my 500 check is caught is pass's that view.

我知道这到处都是.但是,如果我能找到一种方法来调用我的班级而不改变视图,那将是非常有益的.

I know this is kind of all over the place. But if I could find a way to call my class without changing the view it would be immensely beneficial.

推荐答案

只需将loc设置为控制器的url

simply set loc to the url of the controller

$(window).load(function () {
    var url = $('#analyticLog').attr('href');
    loc = /* the URL of the controller you wish to post to */;
    $.ajax({
        type: "POST",
        url: loc,
        success: function(html)
        {
                $("#analyticLogAjax").replaceWith($("#analyticLogAjax",$(html)));
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
          }
    });
});

注意:,除非控制器明确要求post,否则您可能应该使用get

note: unless the controller specifically expects postyou should probably use get

这篇关于Ajax调用不同的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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