I’m trying to use ajax on a select box and change html elements with matching id’s on event of change in select box. I have a code like below but it does not seem to work and rather generates ‘Uncaught ReferenceError: data is not defined’
Below is the code that I am using. Is there something wrong with this?
$('#PolicyCategory').live('change',function(){
var policy = $('#PolicyCategory').val();
var form_data = {
category_id: policy,
ajax: '1'
};
console.log();
alert(data.conn);
$.ajax({
url: "http://coverbuddy.favstay.com/users/category_ajax",
type: "POST",
dataType: "json",
cache: false,
data: form_data,
success: function(data){
alert(data);
}
});
});
The error comes up from
Where you don’t have defined variable
dataas far as we can see from your code.Remove this line or define the variable before you use it.