Search This Blog

Friday, October 20, 2017

When Data Load In Page Then Used Fliting By Using JQuery Method ( Grep,Map,Filter)

LoadAllDocument();
Call   LoadAllDocument() Before Document .Ready Fuction ()
{
}
 
  var glbDate='';
    function LoadAllDocument()
    {
                 $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('NGODocument')/items?$select=Title,Latitude/Latitude,longitude/Longitude,File/ServerRelativeUrl&$expand=Latitude,longitude,File",
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            glbDate=data;
        },
        error: function (error) {
            //alert(JSON.stringify(error));
        }
    });
   
 
    function BindNGOOnFilter()
    {
                             var MasterLstName='NGOEmployee';
                            clientContext = new SP.ClientContext.get_current();
                                web = clientContext.get_web();
                                var list = web.get_lists().getByTitle(MasterLstName);
                                var camlQuery = new SP.CamlQuery();
                                //var q = '<View><Query><Where><Eq><FieldRef Name=\'Section\' /><Value Type=\'Choice\'>'+section+'</Value></Eq></Where></Query></View>';
                                //camlQuery.set_viewXml(q);
                                camlQuery.set_viewXml();
                                this.listItems = list.getItems(camlQuery);
                                clientContext.load(listItems);
                                clientContext.executeQueryAsync(Function.createDelegate(this, this.BindMapOnFilterSuccess),Function.createDelegate(this, this.BindMapOnFilterFailed));
    }
   
                function BindNGOOnFilterSuccess()
                {
                                var totalRow=this.listItems.get_count();
                                var listEnumerator = this.listItems.getEnumerator();
                                while (listEnumerator.moveNext()) {
                             var lstitem = listEnumerator.get_current();
                            var vDetail ='';
                          vDetail +='<div><b>Site Name:</b><span class=\'Italic\'>'+isCheckNull(lstitem.get_item("SiteName"))+'</span></div>';
                          var temparr=GetDocument(lstitem.get_item("Latitude"),lstitem.get_item("Longitude"));
                           $.each(temparr, function (key, value)
                                {
                                                vDetail +='<div class=\'Italic\'><a target=\'_blank\' href=\''+value.File.ServerRelativeUrl+'\'>'+value.Title+'</a></div>';      
                                });
        }
    
                }
                function BindNGOOnFilterFailed()
                {
               
                }
   
                function GetDocument(Latitude,longitude)
                {
                                                                var arr='';
                                                                arr = jQuery.grep(glbDate.d.results, function(key,value) {
                                                                                return ( key.Latitude.Latitude == Latitude && key.longitude.Longitude == longitude);
                            });
                            return arr;
                }
                  

Multiple Ajax Requests with Jquery

Last few days I have been working with APIs for instant search results, I had an idea to implement a super instant search with multiple APIs like twitter, youtube, yahoo and bing. But jquery older versions doesn’t support multiple ajax call-backs, luckily I had found Jquery 1.5 has released a new method called $.when finally I have developed super fast search at kokkoroko.com.

Kokkoroko Super instant search

 Download Script     Live Demo

Javascript Code
Contains javascript and HTML code. $.when( yahoo(), bing()) is the method to call multiple ajax requests. Here $.when calling two functions called yahoo() and bing()callback objects $.done(yahoo_data, bing_data)

<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".search_input").keyup(function()
{
var search_input = $(this).val();
var keyword= encodeURIComponent(search_input);
// Yahoo Search API 
var yahoo_url='http://boss.yahooapis.com/ysearch/web/v1/'+keyword+'?appid=APP_ID&format=json&callback=myData'; 
var bing_url='http://api.search.live.net/json.aspx?JsonType=callback&JsonCallback=?&Appid=APP_ID&query='+keyword+'&sources=web&web.count=10';
// Yahoo API
function yahoo()
{ 
return $.ajax({
type: "GET",
url: yahoo_url,
dataType:"jsonp",
success: function(yahoo_data)
{
}
});
}
// Bing API
function bing()
{ 
return $.ajax({
type: "GET",
url: bing_url,
dataType:"jsonp",
success: function(bing_data)
{
}
});
}
// Multiple Ajax Requests 
$.when( yahoo(), bing()).done(function(yahoo_data, bing_data)
{
var yahoo=yahoo_data[0].ysearchresponse.resultset_web;
var bing=bing_data[0].SearchResponse.Web.Results;
// Yahoo results
if(yahoo)
{
$("#yahoo_result").html('');
$.each(yahoo, function(i,data)
{
var title=data.title;
var dis=data.abstract;
var url=data.url;
var dispurl=data.dispurl;
var final="<div class='webresult'><div class='title'><a href='"+url+"' target='_blank'>"+title+"</a></div><div class='desc'>"+dis+"</div><div class='url'>"+dispurl+"</div></div&gt;";
$("#yahoo_result").append(final); // Result
});
}
// Bing results
if(bing)
{
$("#bing_result").html('');
$.each(bing, function(i,data)
{
var title=data.Title;
var dis=data.Description;
var url=data.Url;
var DisplayUrl=data.DisplayUrl;
var final="<div class='webresult'><div class='title'><a href='"+url+"' target='_blank'>"+title+"</a></div><div class='desc'>"+dis+"</div><div class='url'>"+DisplayUrl+"</div></div&gt;";
$("#bing_result").append(final); // Result
});
}

});

});
});
</script>
// HTML code
<input type="text" class='search_input' />

<div>
<div id="yahoo_result"></div>
<div id="bing_result"></div>
</div>

CSS

#yahoo_result, #bing_result
{
float:left;
width:450px;
}
.search_input
{
border:2px solid #333;
font-size:20px;
padding:5px;
width:350px;
font-family:'Georgia', Times New Roman, Times, serif;
-moz-border-radius:5px;-webkit-border-radius:5px;
}


Unrecognized escape sequence in database connection string c#

When we connect sql database in asp.net web site and make connection on page then many type we face this type of problem.

If you are new and you want to create connection at first time then it is possible that you face this problem.

UNRECOGNIZED ESCAPE SEQUENCE:
As we know that we write fallowing code for make connection.

string connetionString = null;
            SqlConnection cnn ;
     
                     connetionString = "Data Source=PARIJAT-PC\PARIJAT;Initial Catalog=my_testing;Integrated Security=True";

            cnn = new SqlConnection(connetionString);

And get an Exaction or Unrecognized escape sequence error. Because you do not use  \ (forward sales) in string object.

For solving this here we give two option.

Use @ with connectionstring as like :


connetionString = @"Data Source=PARIJAT-PC\PARIJAT;Initial Catalog=my_testing;Integrated Security=True";

Use \\ sales in the place of single sales. Like as :

connetionString = "Data Source=PARIJAT-PC\\PARIJAT;Initial Catalog=my_testing;Integrated Security=True";

Monday, September 4, 2017

People Picker get user name using Rest API



//Content editor code


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet"/> 
<script src="/sites/<Site>/<Subsite>/SiteAssets/RestPeoplePicker.js"></script> 

<input name="fname" id="txtUser" type="text">


//RestPeoplePicker.js


//this function get the user details from current user id
$(document).ready(function()
{
$("#txtUser").autocomplete({
source: search,
minLength: 2
});

});

//Below Function will search the users while typing in the text box function search(request,response) {
//var appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
//var hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
var serverUrl = _spPageContextInfo.webAbsoluteUrl;
var restSource = serverUrl+ "/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";
// var principalType = this.element[0].getAttribute('principalType');
$.ajax(
{
'url':restSource,
'method':'POST',
'data':JSON.stringify({
'queryParams':{
'__metadata':{
'type':'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
},
'AllowEmailAddresses':true,
'AllowMultipleEntities':false,
'AllUrlZones':false,
'MaximumEntitySuggestions':50,
'PrincipalSource':15,
'PrincipalType': 15,
'QueryString':request.term
}
}),
'headers':{
'accept':'application/json;odata=verbose',
'content-type':'application/json;odata=verbose',
'X-RequestDigest':$("#__REQUESTDIGEST").val()
},
'success':function (data) {
var d = data;
var results = JSON.parse(data.d.ClientPeoplePickerSearchUser);
if (results.length > 0) {
response($.map(results, function (item) {
return {label:item.DisplayText,value:item.DisplayText}
}));
}
},
'error':function (err) {
alert("search:"+JSON.stringify(err));
}
});
}

You can also get different properties like Key,Description,Etc instead of DisplayText