Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery AJAX HTML response in error function

var id = 45;        
$.ajax({
            url :'url', // This URL response some HTML content
            type: 'POST',
            dataType: 'json',
            data :{ID:id},
            success:function(data)
            {
                console.log(data); // No Response here
            },
            error : function (error){
                console.log(error); // error.responseText contain html content
            }
        });

I render HTML content by JQuery AJAX. The HTML response comes from error function instead of success function. is any mistake from my side?

like image 573
Ramesh Murugesan Avatar asked May 14 '26 08:05

Ramesh Murugesan


1 Answers

Use html instead of json for datatype

The datatype property specifies the type of data that you're expecting back from the server

$.ajax({
                url :'url', // This URL response some HTML content
                type: 'POST',
                dataType: 'html',
                data :{ID:id},
                success:function(data)
                {
                    console.log(data); // No Response here
                },
                error : function (error){
                    console.log(error); // error.responseText contain html content
                }
            });

See the Jquery Api for more details

Hope this helps.

like image 156
Frebin Francis Avatar answered May 16 '26 23:05

Frebin Francis