jQuery change URL of form submit

后端 未结 2 1187
悲哀的现实
悲哀的现实 2020-12-28 12:16

I want to change the URL the form is submitted to upon click as seen below. Below is what I have tried but it does not work.

相关标签:
2条回答
  • 2020-12-28 12:53

    Send the data from the form:

    $("#change_section_type").live "change", ->
    url = $(this).attr("data-url")
    postData = $(this).parents("#contract_setting_form").serializeArray()
    $.ajax
      type: "PUT"
      url: url
      dataType: "script"
      data: postData
    
    0 讨论(0)
  • 2020-12-28 13:05

    Try using this:

    $(".move_to").on("click", function(e){
        e.preventDefault();
        $('#contactsForm').attr('action', "/test1").submit();
    });
    

    Moving the order in which you use .preventDefault() might fix your issue. You also didn't use function(e) so e.preventDefault(); wasn't working.

    Here it is working: http://jsfiddle.net/TfTwe/1/ - first of all, click the 'Check action attribute.' link. You'll get an alert saying undefined. Then click 'Set action attribute.' and click 'Check action attribute.' again. You'll see that the form's action attribute has been correctly set to /test1.

    0 讨论(0)
提交回复
热议问题