jQuery facebook autocomplete live demo
Following are the code snippet example for Autocomplete (similar the facebook autocomplete).
Code Example:
JQuery Autocomplete similar to facebook
We are Web Technology Experts Team who provide you Important information on Web Development, Interview Questions and Answers, live project problem and their solution and online free tutorials.
JQuery Autocomplete similar to facebook
1) jQuery(this);// Current object
2) jQuery("p");// Select all the P tag
3)jQuery("p.abc");//Select all the P tag having class abc 4) jQuery("ul li:first");//select the first li of ul 5)jQuery("p").hide();// Hide the p tag 6) jQuery(document).ready(function(){ jQuery("button").click(function(){ jQuery("div.toggle").toggle(); }); });:
/*When you click the button first time, it will hide the div having class toggle and when click again will show.*/ 7)jQuery("div#intro .head"); // select the class having "head" under div having id "intro" 8)jQuery("[hrefjQuery='.jpg']"); //select all href having link ending with jpg 9)jQuery("p.abc").append("greatinformations");;// Add the text "greatinformations" end the div having class abc 10) jQuery("p.abc").after("greatinformations"); /*Add the text "greatinformations" after the ending the div having class abc Enter code here. Please note: Although no board code and smiley buttons are shown, they are still usable.*/ 11)jQuery("div").animate({height:300},"slow"); //change all the div height to 300px 12) jQuery(this).css("background-color"); //get the background color of current html object 13)jQuery(this).css("background-color", 'blue' ); //set the background-color to blue of current html object 14)jQuery("div").animate({left:"100px"},"slow"); // Move the div to 100px 15)/*jQuery Callback:A callback function is executed after the current work is done eg. */ jQuery("button").click(function(){ jQuery("div.class").show(300,function(){ alert("The div is display now "); });. 16) jQuery("button.a").click(function(){ jQuery("div").load('abc.txt'); }); /* when click on button having class a will load the data from abc.text and upload to div */ 17) jQuery("div").load('abc.txt','',function(){alert('hi')}); // after loading file abc.txt, alert the "hi"
Async=true
Async=falseAjax request does not execute independently, Its response can comes when earlier request finished.
//serialize ajax Data var formData = $('form#formId').serialize(); $.ajax({ url: '/my/site', data: formData, type: 'post', success: function(result) { console.log(result); } });
$.getJSON("http://twitter.com/status/user_timeline/padraicb.json?count=10&callback=?", function(result){ //Now result have response of ajax call console.log(result); });
if(!empty($_POST)){ echo " "; print_r($_POST); echo ""; /** You can write your code here **/ /** You can write your code here **/ die; }
Array ( [formsubmit] => 1 [first_name] => Raj [last_name] => sinha [email] => raj@no-spam.ws [phone] => 789797522 [city_id] => 1 )
if(!empty($_POST)){ echo " "; print_r($_POST); echo ""; /** You can write your code here **/ /** You can write your code here **/ die; }
Array ( [formsubmit] => 1 [first_name] => Raj [last_name] => sinha [email] => raj@no-spam.ws [phone] => 789797522 [city_id] => 1 )
$cookieValue='This is cookie value'; setcookie('name', $cookieValue, time() + 3600);
$.ajax({ url: '/my/site/url', data: { name: "Arun", location: "Chandigarh" }, type: 'post', success: function(result) { console.log(result); } });
var formData = $('form#formId').serialize(); $.ajax({ url: '/my/site', data: formData, type: 'post', success: function(result) { console.log(result); } });
$.getJSON("http://twitter.com/status/user_timeline/padraicb.json?count=10&callback=?", function(result){ //Now result have response of ajax call console.log(result); });
$.ajax({ url: '/ajax/url', dataType: "json", data: name=encodeURIComponent('Test'), success: function(response) { if(response.success == 1){ offWords = response.data; } }, error: function(xhr, ajaxOptions, thrownError) { } });
$.ajax({ type:"POST", beforeSend: function (request) { request.setRequestHeader("Header-Name", "Header Value"); }, url: "/ajax/url/", data: "name=web", processData: false, success: function(msg) { //Success } });
function getRemote() { return $.ajax({ type: "GET", url: '/ajax/url', async: false }).responseText; }
$.ajaxSetup({async:false});
Access-Control-Allow-Origin: http://www.domain.com
$.ajax({ type:"POST", url: "url", data: "name=web", error: function(xhr, status, error) { var err = eval("(" + xhr.responseText + ")"); console.log(err.Message); } success: function(msg) { //Success } });
var selectedIds = new array(); $("input:checkbox[name=type]:checked").each(function(){ selectedIds.push($(this).val()); }); console.log(selectedIds);
$.ajax({ url: "/ajax/myfile.php", data: 'pro=web+technology+experts+notes', type: "GET", headers: {"X-Test-Header-Key": "header-value"} });
$.ajax({ url: "/ajax/myfile.php", data: JSON.stringify({ field1: 'value1', field2: 'value2',field3: 'value3' }), type: "GET", headers: {"X-Test-Header-Key": "header-value"}, error: function(xhr, status, error) { // when ajax call (get OR POST), failed, this node will be called. //console.log(xhr); } });
$.ajax({ url: "/ajax/myfile.php", data: 'pro=web+technology+experts+notes', type: "GET", headers: {"X-Test-Header-Key": "header-value"}, error: function(xhr, status, error) { // when ajax call (get OR POST), failed, this node will be called. //console.log(xhr); } });
$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) ) .then( myFunc, myFailure );
var formData = $('form').serialize();
var formData = $('form').serialize(); $.ajax({ url: "/ajax/myfile.php", data: formData, type: "GET", headers: {"X-Test-Header-Key": "header-value"}, error: function(xhr, status, error) { // when ajax call (get OR POST), failed, this node will be called. //console.log(xhr); } });
var page=0; $(window).scroll(function() { if($(window).scrollTop() == $(document).height() - $(window).height()) { page++; $.ajax({ url: "/ajax/load-data.php?page="+page,//this must return the html instead of json type: "GET", success:function(data){ //Here data will be all the new html, you need to append this to existing page like below $('#container').append(data); } error: function(xhr, status, error) { // when ajax call (get OR POST), failed, this node will be called. //console.log(xhr); } }); } });
$.ajax({ url: "/ajax/load-data.php", type: "GET", dataType: 'json', success:function(data){ //Now you can handle JSON Response } error: function(xhr, status, error) { //Error handling here } });If there are data in normal text and we want to parse the text with use of parseJSON method. See Example:
$.parseJSON(planTextData);
var stringData='{json:data}'; try { var json = JSON.parse(stringData); } catch(e) { //console.log('invalid json'); }
Access-Control-Allow-Origin: https://www.youwebsitedomain.com
$.ajax({ url: '/ajax', success:function(data, textStatus, request){ console.log(request.getResponseHeader('some_header')); } });
$("input:checkbox[name=type]:checked").each(function() { //JS array of selected checkbox });
function onSubmitFunction(){ $.ajax({ type: "POST", url: "/ajax", data: $('#mytestForm').serialize(), success: function(msg){ //console.log(msg); } }); return false; }
function onSubmitFunction(){ $.ajax({ type: "POST", url: "/ajax", data: $('#mytestForm').serialize(), success: function(msg){ //console.log(msg); }, error: function (request, error) { console.log(arguments); } }); return false; }
var ajaxRequest = $.ajax({ type: "POST", url: "/ajax", data: "name1=value1&name2=value2", success: function(msg){ //here success comes } }); //Abort the ajax request ajaxRequest.abort()
$.ajax({ type: "POST", url: "/ajax", data: "name1=value1&name2=value2", success: function(msg){ if(msg.success){ window.location.href='/newpage.php'; } //here success comes } });
var myArray=new Array(); console.log($.isEmptyObject(myArray));//return true var myArray=new Array('This is message'); console.log($.isEmptyObject(myArray));//return false
function onSubmitFunction(){ $.ajax({ type: "POST", url: "/ajax", data: $('#mytestForm').serialize(), success: function(msg){ if(msg.success){ //here success comes } } }); return false; }
console.log($('textarea#idOfTextArea').val());
function callAjax(url,method) { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200) { //console.log(xmlhttp.responseText); } } } xmlhttp.open(method, url, true); xmlhttp.send(); } callAjax('/ajax?data=1','GET')
$.ajaxSetup ({ // Disable the caching of AJAX responses for all Ajax cache: false });
window.location="/folder/file.pdf"
$.ajax({ url: '/ajax', headers: { 'x-my-custom-header': 'I am good' } });
async: false
$("p").add("div")
$("div.after").find("p").addBack().addClass("background");
$('div.after').after('Test Message');
$(document).ajaxComplete(function(event,request, settings) { alert( "Request Complete." ); }); $( ".trigger" ).click(function() { $( ".result" ).load( "ajax/test.html" ); });
$(document).ajaxError(function(event, jqxhr, settings, exception) { alert( "Request Complete with Error." ); }); $( ".trigger" ).click(function() { $( ".result" ).load( "ajax/test.html" ); });
$(document).ajaxSend(function(event, jqxhr, settings) { alert( "Ajax Request just send" ); }); $( ".trigger" ).click(function() { $( ".result" ).load( "ajax/test.html" ); });
$(document).ajaxStart(function() { alert( "Ajax Request just send" ); }); $( ".trigger" ).click(function() { $( ".result" ).load( "ajax/test.html" ); });
$( ".log" ).ajaxStop(function() { $(this).text( "Triggered ajaxStop handler." ); });
$(document).ajaxSuccess(function() { $( ".log" ).text( "Triggered ajaxSuccess handler." ); });
$('a.clickMe').click(function() { $('#effect').animate({ width: 'toggle', height: 'toggle' }, { duration: 5000, specialEasing: { width: 'linear', height: 'easeOutBounce' }, complete: function() { $(this).after('Animation complete.');} }); });
function submitme(){ var data= $('#form').serialize(); var url ="/ajax/submiturl"; $.ajax({ type: "POST", url: url, data: data, success: function(data){ alert(data); }, dataType: 'json' }); }