REST Web Service client with jQuery -


i'm posting first question cause i'm stuck problem trying call rest web service jquery. here code :

<script>     $("#sellistsub").change(function() {         var listid = $("#sellistsub option:selected").val();         $.ajax({             type : "get",             beforesend : function() {                 headers = {                     'authorization' : 'mykey'                 };             },             url : "https://api.createsend.com/api/v3.1/lists/" + listid + "/customfields.json",             success : function(data) {                 alert("success");                            }         });     }) </script> 

i retrieve option selected in < select > use call ws.

i looked , try every solution i've found on site nothing worked. i've tested url auth header on postman , works fine.

the web service supposed return json object first thing achieve reach success function...

i don't know if can here's equivalent of want in java/jersey (this works) :

string idlist = request.getparameter("sellistsub"); client client = clientbuilder.newclient(); webtarget resourcetarget = client.target("https://api.createsend.com/api/v3.1/lists/" + idlist + "/customfields.json"); string jsoninstring = resourcetarget.request(mediatype.application_json_type).header("authorization", "mykey").get(string.class); 

if see where's mistake, please tell me ; )

regards.

you might wan't change beforesend function below

<script>     $("#sellistsub").change(function() {         var listid = $("#sellistsub option:selected").val();         $.ajax({             type : "get",             beforesend : function(xhr) {                 xhr.setrequestheader("authorization", 'mykey');             },             url : "https://api.createsend.com/api/v3.1/lists/" + listid + "/customfields.json",             success : function(data) {                 alert("success");                            }         });     }) </script> 

update
might want below in beforesend function

  xhr.setrequestheader("accept", "application/json");   xhr.setrequestheader("content-type", "application/json"); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -