Ajax request with multiple web part instances

Hello,

I created a custom web part which makes a $.ajax request to a SharePoint list, the problem is when there are multiple instances of the web part on a page the last request is used for all the web parts. I understand why this is occuring (at least I think I do), is there a way to fix this? Is the problem wpObj is still at a global scope?

I'm using a visual web part, and running my javascript within the ascx. I've created js objects which I thought creating my js objects using constructors would allow me to isolate the calls per object but I guess I'm doing something wrong.

Doing something like the following:

$(document).ready(function(){
var wpObj = new dataObj();
wpObj.getData(url);
function dataObj(){
  this.getData = function(url){
     $.ajax({
      //yada yada yada
     });
  };  
};
});
Thanks for any suggestions
July 3rd, 2013 10:04am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics