views:

972

answers:

1

I am trying to implement autocomeplete box in a custom webpart in sharepoint 2007. When i use a static file in same domain (for textbox with id f1) everything works fine but when I use a remote url that gives a json output (for textbox with id f2), it gives a Permission Denied error in javascript. In the final page following is the HTML generated -

$('#f1').autocomplete('documents/staticfile.txt');
$('#f2').autocomplete('http://url_that_spits_out_json', 
{ dataType:"json", 
  formatItem: function(data,i,max,value,term){ return value; }, 
  parse: function(data) { 
    var array = new Array(); 
    for(var i=0;i<data.length;i++) {
      array[array.length] = { data:data[i], value: data[i].text, result: data[i].text};
    } 
    return array;
  }
});

Since its working fine for f1, to me it looks like something to do with sharepoint. Anyone has any idea, how to do this?

+1  A: 

If you are receiving a permission denied error is most likely because you are getting your JSON data from another domain. You will either have to use JSONP or keep the data on the same domain name.

See $.ajax option for dataType: JSONP

bendewey
http://code.google.com/p/jquery-jsonp/ makes it even easier :)
Julian Aubourg