How to use the response of Ajax Post

enb081

I make an ajax POST request to post JSON data to server, and I get a simple text response. I can see that everything works fine because it is shown in the browser's debugger. However, I cannot use it.

    callajax1(Callback);


    function callajax1(callbackfn) {   
    $.ajax({
        type: "POST",
        url: myUrl,
        data: JSON.stringify({ Data: data }),
        contentType: "text/plain; charset=utf-8",
        dataType: "json",
        success: function (data2) {
            callbackfn(data2);
        },
        failure: function (errMsg) {

        }
    });
    return false;
}


function Callback(data) {
    alert(data);
}

No alert is showing.

Quentin

You say that you are getting a "simple text response" back, but your JavaScript (dataType: "json") says to ignore the content type of the response and parse it as JSON.

Perhaps (since you are sending JSON and claiming it is plain text) you are confusing dataType (override the content type the server returns) and contentType (describe the data you are sending).

If the response is "simple text" and not JSON then you can't parse it as JSON. Either return JSON or use dataType: 'text'.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to format the response of ajax POST request?

From Dev

How to implement PRG pattern and still use Ajax post response in asp mvc 4?

From Dev

How do I use Ajax to Post only 1 value of an array at a time sequentially and wait for the response before proceeding?

From Dev

how to use AJAX post in django

From Dev

Empty post response ajax

From Dev

rerturning response of an ajax post

From Dev

Ajax POST - display response

From Dev

How to use ajax response JSON data?

From Dev

how to use ajax response in attr of an element

From Dev

How to pass and use a success/failure response with AJAX

From Dev

How to handle a multiple files response from a Ajax POST request?

From Dev

How to get response headers from ajax post request

From Dev

How to use Ajax to post and then replace div

From Dev

How to use magnific popup with ajax post and url?

From Dev

How to use ajax to post some content and then to retrieve it?

From Dev

how to use laravel5 ajax post

From Dev

How to use Ajax to post and then replace div

From Dev

How to use magnific popup with ajax post and url?

From Dev

how to use laravel5 ajax post

From Dev

How to use ajax to post wordpress comments?

From Dev

POST a response from API by AJAX

From Dev

Ajax post json response issue

From Dev

POST a response from API by AJAX

From Dev

AJAX $.post not showing response data

From Dev

Laravel Ajax response post method

From Dev

How to use ajax response list as struts2 iterator value?

From Dev

How to use ajax response list as struts2 iterator value?

From Dev

How to convert ajax response and use for-each loop in blade template?

From Dev

use $.ajax into $.post?

Related Related

HotTag

Archive