Tuesday 21 May 2013

Textual description of firstImageUrl

Post JSON request Using JQuery 1.9 And AJAX

Create a json string from user inputs in html form and post it using ajax :
To create a json string from user inputs , first create a javascript map object and put name value pairs in the map , then use Json 2to create a json string from this json object .To post the request , use $.ajax function of jquery . If you want to block the screen while ajax response comes from the server , you can use Block UI in the beforeSend function.Here is the code

var jsonMap = new Object();
     
     jsonMap['maps'] = map;
     jsonMap['input1'] = $("#formInput1").val();
     jsonMap['input2']="input2";
     
         
     var datastring = JSON.stringify(jsonMap,null);
      
     var request=$.ajax({
        type: 'POST',
        url: "rest/executerequest#!",
        data: datastring,
        contentType: 'application/json; charset=utf-8',
        dataType:'json',
        beforeSend:function(xhr){
         $.blockUI({ message: '<h1><img src="images/loader.gif" /> Just a moment...</h1>' });
        
        }
        });

 request.done(function(msg) {
  alert('success');
      }
       );

Post Comments !!