What I am doing:
I am retrieving list items from list using javascript as per visual webpart custom property. I have created a dropdown in webpart editor part from where I am getting site url. As per site url, I am retrieving list items from that perticular site.
My Problem:
My problem is that when I am adding same webpart multiple times on single page then all my javascript functions and variables are conflicting. So, that only one webpart is working and other is not.
Example:
Page1.aspx
Webpart1
<script type="text/javascript">
var x,y;
function temp(siteurl){
var ctx,web;
var a,b,c,d;
x = siteurl;
getweb();
if(siteurl == 'xyz'){
a = a+b;
}
else{
a = c+d;
}
alert("Items of site:"+siteurl);
//append list items to div with classname 'myclass'
}
function getweb(){
alert(x);
}
</script>
<div class='myClass'>
</div>
<script type="text/javascript">
$(document).ready(function () {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', temp);
});
</script>
Webpart1 ( add same webpart on page again with different property[siteurl value] )
// same as above
<script type="text/javascript">
var x,y;
function temp(siteurl){
var ctx,web;
var a,b,c,d;
x = siteurl;
getweb();
if(siteurl == 'xyz'){
a = a+b;
}
else{
a = c+d;
}
alert("Items of site:"+siteurl);
//append list items to div with classname 'myclass'
}
function getweb(){
alert(x);
}
</script>
<div class='myClass'>
</div>
<script type="text/javascript">
$(document).ready(function () {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', temp);
});
</script>
I am executiong query with context.executeQueryAsync(success,failed)
.
Any Solution ?