Friday, 16 September 2016

JQuery ajax GET request call

Below is the example of an jQuery ajax call. It's making a GET request.

 <head>  
      <script>  
      $( document ).ready(function() {  
           $( "#mainMenuArea" ).load( "html/mainMenu.html" );  
           $.ajax({url: "http://localhost:8080/services/usersproducts/allproduct",   
             success: function(result){  
                var productArray = result.products  
                $( "#div_appArea" ).append("<table>");  
                $( "#div_appArea" ).append("<tr><th>Mobile No<th><th>Possession Status<th>");  
                $( "#div_appArea" ).append("<th>Company Name<th><th>Recommended<th></tr>");  
                $( "#div_appArea" ).append("<th>User Product Id<th><th>Recommended<th></tr>");  
                for(var i in productArray){  
                     $( "#div_appArea" ).append("<tr>");  
                     $( "#div_appArea" ).append("<td>"+productArray[i].productId+"<td>");  
                     $( "#div_appArea" ).append("<td>"+productArray[i].productName+"<td>");  
                     $( "#div_appArea" ).append("<td>"+productArray[i].companyName+"<td>");  
                     $( "#div_appArea" ).append("</tr>");  
                }  
                $( "#div_appArea" ).append("</table>");  
        }});  
      });  
     </script>  
 </head>  
 <body>  
     <div id="div_appArea">  
 </body>  

No comments:

Post a Comment