Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

javascript ajax post

function Inint_AJAX() 
{

   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;

}

var http = Inint_AJAX(); var url = "example.php"; var params = "content=1"; http.open("POST",url+"?"+params, true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() {//Call a function when the state changes. if(http.readyState == 4 && http.status == 200) { document.getElementById('divid').innerHTML=http.responseText; //retuen value }

Jquery infinite scroll - with div

This code has been tested and verified as working. When you scroll your div, the code checks if the scroller reached to the bottom by comparing the scroller height against the scroller position. If so, it calls to a method that gets more content and append it to the div.

    
        Test 
        
        
    
        
            

This is the div content

This is the div content

This is the div content

This is the div content

This is the div content

This is the div content

Scroll Height:
Scroll position:

Simple AJAX - PHP and Javascript

this tutorial I will show you the most basic way to get a response from a PHP script.and we will start with the base object you need: a XMLHTTP Javascript object. With this object you call a server-side script and get the response back. Most browsers use the same Javascript object, but of course Microsoft has to be different, so they require their own. The following function will return the correct object:
function Inint_AJAX() {

   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE

   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE

   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript

   alert("XMLHttpRequest not supported");

   return null;

};
This code will, again, return an XMLHTTP object to use in our Javascript. What is going to happen is that we are going to use this object to make an HTTP request through Javascript. When we get a response back, we will simply place it in the page, nothing fancy. In order to make the request we use the following code:
function ajaxfun(src)

{

     var req = Inint_AJAX();

     req.onreadystatechange = function () { 

          if (req.readyState==4 && req.status==200) {

                  document.getElementById('divid').innerHTML=req.responseText; //retuen value
          }

     };

     req.open("GET", "demo.php?src="+src); //make connection

     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header

     req.send(null); //send value

   

}

Add and Remove HTML elements using javascript





Email Validation in javascript

Email Validation in javascript
function isValidEmail(content)
{

valid = false;


var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;


if (filter.test(content)) {
valid=true;
}

return valid;
}

Phone Validate in js

Phone Validate in js
function validatephone(xxxxx) {
  var maintainplus = '';
  var numval = xxxxx.value
  if ( numval.charAt(0)=='+' ){ var maintainplus = '+';}
  curphonevar = numval.replace(/[\\A-Za-z!"£$%^&*+_={};:'@#~,¦\/<>?|`¬\]\[]/g,'');
  xxxxx.value = maintainplus + curphonevar;
  var maintainplus = '';
  xxxxx.focus;
}