0

I want to get data using a GET request and save into data.

I have written below code but it is not working can any one give answer to save data in database

$(document).ready(function() {
  $.ajax({
    url: "https://www.zoya.in/wps/proxy/https/tsweb.titanprodlive.crown.in/wcs/resources/store/10151/storelocator/cities?supportedBrand=ZO",
    type: 'GET',
    dataType: "jsonp",
    async: false,
    crossDomain: true,
    contentType: 'application/json',
    secure: true,
    processData: false,
    // contentType: false,
    headers: {
      'Access-Control-Allow-Origin': '*',
      "Content-Length": "<calculated when request is sent>",
      "Host": "<calculated when request is sent>"
    },
    beforeSend: function(xhr) {
      xhr.setRequestHeader("Authorization", "Basic VGl0YW5fTXVsZTphZG1pbl90IXRhbl9tdWxl");
    },
    success: function(result) {
      // var res = $.parseJSON(result);
      console.log('city result:-  ');
    },
    error: function(xhr, status, error) {
      console.log(error);
      // alert(xhr.responseText);
    }
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
dev.aashu
  • 1
  • 2
  • 1
    Hello and welcome to stackoverflow, can you share which error message do you receive after executing this code please ? – sohaieb azaiez Sep 14 '22 at 08:28
  • The endpoint you're calling returns JSON, not JSONP. I presume you've set that `datatype` in an effort to get around the CORS error you first encountered, but won't fix the problem. If there's no CORS headers included in the response then you will need to make the call from the server side, not client-side. See the duplicate I marked for more information on this. Also, for future reference, ***never*** use `async: false`. It's incredibly bad practice. – Rory McCrossan Sep 14 '22 at 08:35
  • @RoryMcCrossan will can you give exact code that runs, i m new to this concept – dev.aashu Sep 14 '22 at 08:49
  • That's the point, *you* will need to write the code to make this request on the server side, in whatever language your server platform supports, to proxy the request. It shouldn't be hard to find an example of how to do this in Google: 'how to send http request in [language here]' – Rory McCrossan Sep 14 '22 at 08:52

0 Answers0