Uberswe
Uberswe

Reputation: 1058

Changing $.post to $.ajax not working?

I have a form which updates with more content after clicking submit. all elements for this part are already in DOM. I was having issues with $.post because it is asynchronous and tried switching to $.ajax but now nothing happens when I click submit on this part of the form.

Not working:

$.ajax({
            type: 'POST',
            url: 'functions/flow.php',
            data: {
                step: 3, 
                id: question_id
            },
            async: false
        }).done(function(data) {
            $('#fourth_step .form').append(data); 
        }); 

This works:

$.post("functions/flow.php", {
            step: 3,
            id: question_id
        }, function(data) {
            $('#fourth_step .form').append(data);
        }
        );

I tried using .fail to see if i got an error but nothing seems to happen, it just stops.

Thanks for the help.

Upvotes: 0

Views: 103

Answers (3)

coolguy
coolguy

Reputation: 7954

$.ajax({
            type: 'POST',
            url: 'functions/flow.php',
            data: {
                step: 3, 
                id: question_id
            },
            async: false,
            success:function(data){
              $('#fourth_step .form').append(data); 

             }
});

Upvotes: 1

Rab
Rab

Reputation: 35572

$.ajax({
  type: 'POST',
  url: 'functions/flow.php',
  data: '{"step":3,"id":'+question_id+'}',
  async: false
  success: function(data) {
    $('#fourth_step .form').append(data); 
  }
});

Upvotes: 0

Ohgodwhy
Ohgodwhy

Reputation: 50767

$.ajax({
  type: 'POST',
  url: 'functions/flow.php',
  data: "step="+3+"&id="+question_id,
  async: false
  success: function(data) {
    $('#fourth_step .form').append(data); 
  }
}); 

Upvotes: 0

Related Questions