Smajl
Smajl

Reputation: 7995

Ajax POST - display response

I would to display a response body of Ajax POST request on my page:

 $.ajax({
    type: "POST",
    url: "<url>",
    data: jsonText,
    crossDomain: true,
    dataType: "text/plain",
    contentType : "application/json",

    //if received a response from the server
    success: function(response, textStatus, jqXHR) {
            alert(response);
            $("#uploadResponse").innerHtml = response;
    },

    });

I get response with response but the success function is not triggered and I see not output. Why is that?

Upvotes: 1

Views: 3299

Answers (1)

Jai
Jai

Reputation: 74738

Because jQuery objects can't have DOM methods and jQuery methods can't be applied on raw DOM elements as well. So you need to apply jQuery method to jQuery object and vice versa.

And one thing to be noticed innerHTML is the actual method not innerHtml.

Either do this:

$("#uploadResponse")[0].innerHTML = response;

or within jQuery:

$("#uploadResponse").html(response); // or .text(response);

The dataType is seemingly doubtful change to dataType:"text" only.

Upvotes: 2

Related Questions