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!
You can just remove the option “
dataType:html,” to let$.ajaxdeduce the datatype.But, to answer the question, the right syntax id
dataType:'html'with quote because it is not a variable