Home Ajax script does not update DOM
Reply: 1

Ajax script does not update DOM

Homewrecker
1#
Homewrecker Published in 2017-12-07 15:36:15Z

I have a little Ajax script that executes a POST and returns the result on screen. I debugged the script and I can see that the POST is successful, however I cannot get the result displayed on screen. It looks like I need an extra refresh or something. Any ideas what's wrong?

Thanks in advance Regards

$(document).ready(function() {

    $("#vehicleMessages").submit(function(event) {
        event.preventDefault();
        ajaxPost();

    });

});

function ajaxPost() {

    var form = $("#vehicleMessages");

    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: form.attr("action") + "?tripId=" + $("#tripId").val() + "&partitionKey=" + $("#partitionKey").val(),
        dataType: 'json',
        success: function(result) {
            if (result.status == "Done") {
                $("#postResult").html("Result: " + result.data);
            }
        }
    });
}
Ben Thomas
2#
Ben Thomas Reply to 2017-12-07 16:44:51Z
  1. You have to be sure that the result.status is "Done".
  2. You have to be sure that the result.data is text or HTML-text

I suggest you to try this:

 $.ajax({
     type: "POST",
     contentType: "application/json",
     url: form.attr("action") + "?tripId=" + $("#tripId").val() + "&partitionKey=" + $("#partitionKey").val(),
     dataType: 'json'
 }).then(function (result) {
     if (result.status == "Done") {
         $("#postResult").html("Result: " + result.data);
     }
 });
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.333134 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO