1

I'm using AJAX to send inputted data to the database which I've managed to achieve. Where I'm struggling is on the success parameter. I'm trying to load and then append a PHP file once the initial AJAX call is successfully completed.

var data = $("#form_write_post").serializeArray()

$.ajax({
    type: "POST",
    url: $("#form_write_post").attr("action"),
    data: data,
    async: false,
    success: $.get("test.php", function(data) {
        $('ul.timeline').append(data);
    });
});

I managed to append JavaScript data but I need to be able to get other data from the database.

Thanks

J. Edd
  • 11
  • 1
  • possible duplicate of [jQuery Ajax POST example with PHP](http://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php) – gpinkas Sep 07 '15 at 11:52
  • Create function for getting data from `test.php` and on first ajax success call it: function refreshData() { $.ajax({ type: "GET", url: 'test.php', success: function(data) { $('ul.timeline').append(data); }; }); } and in saving ajax success call it: success: function(data) { refreshData(); }; – Taron Saribekyan Sep 07 '15 at 12:15

1 Answers1

2

remove $.get(){} in success

$.ajax({
    type: "POST",
    url: 'test.php', //if ur action is test.php
    data: data,
    async: false,
    success: function(data) {
        $('ul.timeline').append(data);
    });
});
Nagesh Sanika
  • 1,090
  • 1
  • 8
  • 16