Problems using $.ajax when creating a wigdet
Hi
I'm trying to create a widget, and at somepoint I need to make an ajax request using $.ajax. The problem is that I can't access the options variables in the ajax .done event. What I'm doing wrong? Here is a simplified version of the code. I'm getting
Cannot set property 'data' of undefined
in line 25. If I try to work the variables outside the ajax function everything works fine. Thank you
- $(function(){
- $.widget("custom.imagesManager",{
- options:{
- url:'test.php',
- post_data:0,
- data:null;
- },
- _create: function(){
- this._refresh();
- },
- _refresh: function(){
- $.ajax({
- type:'POST',
- url:this.options.url,
- data:this.options.post_data,
- dataType: 'json',
- cache:false
- })
- .done(function(data){
- this.options.data = data;
- });
- }
- });
- });