Monday, 30 September 2013

By using JQuery to Post the response to Server

<div id="whole">      
    <div>First Name: <input type="text" id="first" value="creatersite"></div> <br />  
    <div>Last Name: <input type="text" id="last" value="Web Developer"></div> <br />  
    <div align="center"><input type="button" value="submit" onClick="doAjaxPost()"></div>  
<script type="text/javascript" src="jquery-1.4.2.js"></script>  
    function doAjaxPost() {  
     // get the form values  
     var field_a = $('#first').val();  
     var field_b = $('#last').val();  
       type: "POST",  
       url: "serverscript.php",  
       data: "firstname="+field_a+"&lastname="+field_b,  
       success: function(resp){  
         // we have the response  
         alert("Server said:\n '" + resp + "'");  
       error: function(e){  
         alert('Error: ' + e);  

No comments:

Post a Comment