javascript - Ajax Post request formation while calling the api -


i configuring ajax post request hit api.

below curl command (its dummy):

curl -x post \ --header 'content-type: application/json' \ --header 'accept: application/json' \ --header 'authorization: token' \ --header 'timestamp: test' \ --header 'sourcesystemid: test' \ --header 'sourcesystemuserid: test' \ --header 'sourceserverid: test' \ --header 'trackingid: test' \ -d '{"accountid": "123456789","modeofbusiness": "audio"}' \ 'https://services-services.c1.com:443/api/customer/v1/services/querysummary' 

need reform hit using ajax request. ajax code this? how pass --header , -d tag in this? api returning response in json format. below ajax code.

var accntno = document.getelementbyid('accntnotext').value; var token = document.getelementbyid('tokentext').value; //event.preventdefault(); var queryapi = "https://services-services.c1.com:443/api/customer/v1/services/querysummary"; $.ajax({         url: queryapi,         method: 'post',         datatype: "json",         data: { accountid: accntno, modeofbusiness: "audio"},         headers: { 'authorization': token,'timestamp': 'test', 'sourcesystemid':'test','sourcesystemuserid': 'test', 'sourceserverid':'test','trackingid': 'test','content-type':'application/json'},         success: function (data) {                         alert(data); } }); 

for starters:

  1. your curl has accountid , jquery has accountnumber
  2. your http method post , not post
  3. your jquery headers missing accept , has weird whitespace in content-type

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -