0

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 try:

$(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 try:

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

});

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.

littlevahn
  • 637
  • 2
  • 8
  • 25
  • I added those pieces as reference and this might turn out to be a java question if my view controller needs revamping. The real issue is i dont know where the solution might come from. I also had some formatting issues and was not intended them to be viewed as languages. – littlevahn Sep 19 '12 at 17:21
  • What are you trying to do in controllerB? get some data? – wirey00 Sep 19 '12 at 17:26
  • Essentially yes. I really just need data from the front end to be passed to Controller B. B does not need to pass anything back. It just needs to do its own work. The Ajax piece was repopulating a dummy div. Ghetto I know but i was getting desperate. – littlevahn Sep 19 '12 at 17:28

1 Answers1

1

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);
          }
    });
});

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

Rune FS
  • 21,497
  • 7
  • 62
  • 96
  • wow thank you. I didnt realize you had to use the loc var key. – littlevahn Sep 19 '12 at 17:55
  • the loc was what you used in your code. if the `$('#analyticLog').attr('href')` holds the value you can assign that straight to the url property – Rune FS Sep 19 '12 at 19:01