3
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?

3
  • what is the error message? Commented Feb 25, 2015 at 11:42
  • which server side technology you are using? Commented Feb 25, 2015 at 11:42
  • 1
    if you are returning html from server then instead of dataType: 'json' use dataType: 'html' Commented Feb 25, 2015 at 11:43

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

i don't get your question ?
i think Ramesh Murugesan know already that the result is an HTML content :)
@FrebinFrancis Thanks mate.. It works :) dataType should be in html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.