JQuery ajax send json and return html

I want to make an ajax call with parameters. I want to send parameters as json or as text if possible.

The result is returned as html content type.

So this is what I tried

  var data2 = {
      'some-id': 5
  };

  $.ajax({
        type: "POST",
        url: /* some url */,
        data: JSON.stringify(data),
        dataType: 'json',
        success: function(data){      
            //some logic
        }
   }).fail(function() {
            //some error logic
   });

      

The problem is ajax failed with the message "undefined" because it expects html as a response, however my action is returning html.

How can I get this to work with the html response?

+3


source to share


1 answer


Just set "dataType" to "html".

The "dataType" parameter is the type expected in the jQuery ajax call.



More information: http://api.jquery.com/jQuery.ajax/

+10


source







All Articles