java - Secure jsonp ajax calls -
i have developed restful web-service returns jsonp objects. using web-service in simple html page using ajax calls. means @ client side there html page access web-service. no server used @ client side. running page browser. problem can access web-service have implemented. want make secure kind of authentication. have read solution send token along request @ client side don't have server or anything, simple html page. please me solution secure web-service.
javascipt function call webseive:
function calculatepremium(investmentamount,month, premium) { var url = "http://192.1.200.107:8080/webresources/avestwebservice/getpremium"; var payloaddata = { amount: $("#"+investmentamount).val(), period: $("#"+month).val() }; $.ajax({ type: "get", url: url, cache:false, crossdomain:true, data: payloaddata, datatype: "jsonp", success: function (data,textstatus,jqxhr) { $("#"+premium).val(data.premium); }, error: function (jqxhr,textstatus,errorthrown) { alert('error occured'); } }) };
with ajax request can send authentication headers
beforesend: function(xhr) { xhr.setrequestheader("authorization", "basic " + "username:password"); },
or insert authentication data with:
$.ajax({ type: "get", username: "user", password: "password", .... }
but have handle authentication in web-service. or add var payloaddata custom authentication data check web-service.
you should consider make connection under https if don't want other people intercept authentication packets
Comments
Post a Comment