31 March, 2015

REST Call Using jQuery AJAX

Here you can see how you can make REST service call using jQuery :




$(document).on('ready',function(){
            var username ="vachhani_22kk@yahoo.com";
            var password ="password"; 
            function make_base_auth(user, password) {
              var tok = user + ':' + password;
              var hash = btoa(tok);
              return "Basic " + hash;
            }
                $.ajax({
                  url: 'http://google.com/api/jsonws/ocd-ws-portlet.ocdwebs/get-folder-files/folder-id/22793/repository-id/12368',
                  dataType: "json",
                  data:{},
                  type: "get",
                  success: function(data){
                          alert("hi");
                  },
                  beforeSend: function(xhr){
                          xhr.setRequestHeader('Authorization',make_base_auth(username, password));
                                    },
                                    complete: function(){
                                    },
                  error: function(){
                  }
                });
             
 });

Rate Me:

0 Discussion: