Nick Bewley
Nick Bewley

Reputation: 9289

Jquery Ajax DataType 'html is not defined'

I am trying to get my jquery ajax working properly, but facing a ReferenceError when developing with Firebug:

jQuery(document).ready(function() {
    jQuery('.my-div').click(function(e){
    e.preventDefault();
    var href = jQuery(this).attr('href');
    jQuery.ajax({
      type: "POST",
      url:href,
      dataType:html,
      success: function(data, status, xhr){ $('#div_to_load_html').html(data); },
      error: function(){ alert("Error"); },
    });
    });
})

html:

<div class='my-div'><a href='/place/to/go/'>GO!</a></div>

When I click 'my-div', Firebug returns: ReferenceError: html is not defined @ http://www.mydomain.com/:38, which references the line from my jquery dataType:html.

Thanks for your ideas!

Upvotes: 0

Views: 4662

Answers (3)

Lasantha Bandara
Lasantha Bandara

Reputation: 809

this

dataType:html,

line should be corrected as

dataType:'html',

you have to necessarily use this line in some browsers like firefox. Unless you will get an error where you attach the result into the page.

Upvotes: 1

user626963
user626963

Reputation:

You need to pass a string: dataType:'html',

Upvotes: 3

sdespont
sdespont

Reputation: 14025

You can just remove the option "dataType:html," to let $.ajax deduce the datatype.

But, to answer the question, the right syntax id dataType:'html' with quote because it is not a variable

Upvotes: 5

Related Questions