Mohsin Arif

Mohsin Arif

  • 295
  • 6k
  • 137.8k

API show 400 Bad Request

Nov 20 2019 6:21 AM
  1. $.ajax({  
  2.              url: 'https://api.punjab-zameen.gov.pk/api/tehsil/getAll',  
  3.              type: 'GET',  
  4.              contentType: "application/json;charset=utf-8",  
  5.              beforeSend: function (xhr)  
  6.              { xhr.setRequestHeader('Authorization', 'token-Value'); },  
  7.              headers: {  
  8.                  Accept: "application/json;charset=utf-8",  
  9.                  "Content-Type": "application/json;charset=utf-8"  
  10.              },  
  11.              accepts: {  
  12.                  text: "application/json"  
  13.              },   
  14.              success: function (response) {  
  15.                  console.log("dfsdfs");  
  16.                  $.toaster({ priority: "success", title: "Congrat!", message: "Data loading...." });  
  17.                  //LoadDataTable(aDemoItems);  
  18.              },                  
  19.              error: function (response) {  
  20.                  $.toaster({ priority: "danger", title: "oooppss!", message: "failed" });  
  21.                  console.log(response);  
  22.              }  
  23.          })  
i want to send call on this api and get response but when i send without headers then it shows same response of missing authorization token . but when send header so show 400 bad request error 
please help.
 
 
 
show this error in browser
Access to XMLHttpRequest at 'https://api.punjab-zameen.gov.pk/api/tehsil/getAll' from origin 'http://localhost:62245' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
(index):206
 
 
thanks in advance  

Answers (2)