Post form in JQuery and populate DIV - broken in IE

后端 未结 1 1519
我在风中等你
我在风中等你 2021-01-17 07:00

I am trying to create a form that posts data via jQuery and populates the return into the same DIV. This way the page does not refresh on post action.



        
1条回答
  •  暖寄归人
    2021-01-17 07:33

    I would say that you don't have to use the form tag at all in this scenario.

    Edit As Paolo Bergantino said I would also avoid using the inline javascript. So instead use:

    Javascript

    $(document).ready(function() {
      $('.formSubmitButton').click(function() {
          $.post('/add_value', {'test':'test'}, function(data) {
              $("#add_value_form").empty().append($(data));
          }, "text");
      });
    });
    

    Update Since this is still causing a problem, I would perform some testing with the $.ajax method. Also, I don't believe that POST calls would ever get cached, but just in case try setting the cached to false. Another test, to make sure your not having a serialization issue, is to pass your data in already encoded. And if your still having issues you can try to set your dataType to text

    $.ajax({
      url: '/add_value',
      type: 'POST',
      cache: false,
      data: 'test=testValue',
      dataType: 'text',
      complete: function(xhr, textStatus) {
        alert('completed');
      },
      success: function(data) {
        alert(data);
      },
      error: function(xhr, textStatus, errorThrown) {
        alert('woops');
      }
    });
    

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