开发者

Call server method using JQuery

开发者 https://www.devze.com 2023-03-09 01:01 出处:网络
I have an issue regarding to call a server method from Freemarker . The following piece of code works on Google Chrome but not over IE :

I have an issue regarding to call a server method from Freemarker . The following piece of code works on Google Chrome but not over IE :

$(document).ready(function() {
     $('#uploadFileButton')[0].addEventListener('click', function (event) {
                    alert("here @ Upload event");
                        $('#form').attr('action', "[@spring.url '/test'/]");
                        $('#form').submit();
                        return false;
                    }, false);
 });

After investigation , I have found out that I should use attachEvent . However , it still doesn't work over IE

Any tips !!


EDIT: Additional information incorrectly p开发者_开发问答osted as an answer:

I just would like to update you with my latest status . I use the following :

$(document).ready(function() {

$('#uploadFileButton').click(function() {
    alert("here @ Upload event");
    $('#form').attr('action', "[@spring.url '/test'/]");
    $('#form').submit();
    alert("AfteZ Submit");
    return false;
});

}); The problem now that the two alerts I have is working fine . This means that the submit is not working properly .However this url was working on Chrome b4 I use the "Click" instead of "addEventListener" Any Tips !!


$(function() {
     $('#uploadFileButton').click(function() {
        $('#form').attr('action', "[@spring.url '/test'/]").submit();
     });
});

If you're using jquery 1.6.1, then you should probably use .prop() instead of .attr()


jQuery has itself ways for attaching click events in a crossbrowser way with the click function:

$(document).ready(function() {
    $('#uploadFileButton').click(function() {
        alert("here @ Upload event");
        $('#form').attr('action', "[@spring.url '/test'/]");
        $('#form').submit();
        return false;
    });
});


The answer is :

$('#uploadFileButton')[0].attachEvent('onclick', function (event) {
      $('#form').attr('action', "[@spring.url '/evidence/metabolomicsDataset/uploadParameters'/]");
      $('#form').submit();
      return false;
    });

IE understands both "attachEvent" & "onclick" :)

0

精彩评论

暂无评论...
验证码 换一张
取 消