简体   繁体   English

Jquery 帮助提出 ajax 请求

[英]Jquery help making ajax request

I am trying to make an ajax request.我正在尝试提出 ajax 请求。 Now when I click on a option in my form there is no ajax request made.现在,当我单击表单中的一个选项时,没有发出 ajax 请求。 But I go to the right page.但是我 go 到了正确的页面。

My Jquery:我的 Jquery:

$(document).ready(function() {
    // send form ved klik paa listen
    $('option').click(function ()
    {
        var form=$(this).closest('form');
        $.ajax({
          type:'post',
          url:form.attr('action'),
          data:form.serialize(),
          success:function(msg){
            $('#formcontent').html(msg);
          }
        });
    });
});

$().ready(function() {
    $('#jump_nav_submit').hide();
});

$('#jump_nav').live('change', function() {
    window.location = "\/finder\/" + $(this).val();
});

How do I made the ajax request, so that it renders in the div with the ID formcontent and the URL is finder/whateverthevalueofthe option is.我如何提出 ajax 请求,以便它在具有 ID formcontent 的 div 中呈现,并且 URL 是 finder/whateverthevalueofthe option。

I have tried to remove this:我试图删除这个:

$().ready(function() {
    $('#jump_nav_submit').hide();
});

$('#jump_nav').live('change', function() {
    window.location = "\/finder\/" + $(this).val();
});

But the ajax request is not working because the parameter are: http://localhost:3000/finder/?id=16&utf8=%E2%9C%93但是 ajax 请求不起作用,因为参数是: http://localhost:3000/finder/?id=16&utf8=%E2%9C%93

Instead of: http://localhost:3000/finder/1而不是: http://localhost:3000/finder/1

The option element does not support a click event cross browser. option 元素不支持点击事件跨浏览器。 It works in Fifrefox but not in ie, cant remember about chrome/safari.它在 Fifrefox 中有效,但在 ie 中无效,不记得有关 chrome/safari 的信息。

Regardless to support all browsers you will have to do your ajax call in the select change event.无论要支持所有浏览器,您都必须在 select 更改事件中进行 ajax 调用。

Your code snippet does not make it obvious what your trying to achieve in terms of an option click then a redirect on the select change event so hard to advise further.您的代码片段并没有清楚地表明您试图通过单击选项然后重定向 select 更改事件来实现什么,因此很难进一步建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM