Re: Regarding Ajax in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



//   Calling Javascript Function

<input name="word" id="word" tabindex="1" type="text" 
class="top_search_input" onKeyUp='JavaScript:xmlhttpPost
("searchfunc.php","result")'> 
	<!-- inner search start here -->
		<div id="result">&nbsp;</div>	
	<!--inner search start here-->



//   Calling Javascript Function



create a php file(searchfunc.php), that simply displays the data 
results (either query results) / divs / tables / anything you wish to 
return in result



////  Javascript file :

// JavaScript Document
function xmlhttpPost(strURL,dv) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-
www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText,dv);
        }
        if (self.xmlHttpReq.readyState == 1) {
			document.getElementById(dv).innerHTML = '<img 
src="images/search_images/ajax-loading.gif" />';
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    var word = document.getElementById('word').value;
    var loc = document.getElementById('loc').value;
	if(word!=null){
		qstr = 'w=' + escape(word);  // NOTE: no '?' before 
querystring
		if(loc!=null)
			qstr = qstr + '&l=' + escape(loc);  // NOTE: 
no '?' before querystring
	}
    return qstr;
}

function updatepage(str,dvs){
		document.getElementById(dvs).innerHTML = str;
}


/// Javascript File





--- In php-objects@xxxxxxxxxxxxxxx, vijaya lakshmi Vulli 
<vijayalakshmivulli@...> wrote:
>
> Hi All,
>   I am doing One Consultancy project.I am new to PHP with AJAX.In 
php how to do ajax and modal popups and displaying loading and so 
on.If any body have sample examples php with ajax please send it me.
>  
> thank you in adavance
>  
> vijaya
> 
> 
>       
> 
> [Non-text portions of this message have been removed]
>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux