Reputation: 9289
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
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
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