Weird behavious in JQuery.ajax()
The code below is part of an autocomplete input created using JQuery UI.
But my question here is related to the JQuery-AJAX part only.
- change: function(event, ui){
- $.ajax({
- type: "POST",
- url: "includes/c_t_v_choices.php",
- data: { filter: ui.item.value },
- //dataType: "JSON",
- }).done(function( msg ) {
- c_t_v_choices = msg;
- alert( "Data Saved: " + c_t_v_choices );
- $("#c_t_v").autocomplete("option", "source", c_t_v_choices);
- });
The last line in the c_t_v.php file is:
- echo json_encode($return_arr);
The way the code is currently, I see valid data in the alert, sent by the php file. An example is shown below:
- Data Saved: [{"label", "value"}, {"label", "value"}...]
However, when I enable the line:
- dataType: "JSON",
I see something like:
- Data Saved: [object: Object], [object: Object]
Can anyone please help me understand why this weird behavior?
On a side note, any idea why $("#c_t_v").autocomplete is accepting the source i am providing in the code below (which is part of the code above):
- $("#c_t_v").autocomplete("option", "source", c_t_v_choices);