L
L
lilandre2017-10-09 13:52:45
JavaScript
lilandre, 2017-10-09 13:52:45

Why does the Api request to New Mail not work?

You need to make two inputs. In one, it will be necessary to enter the name of the city and have hints, with the presence of a city with such a part of the text. In the second, the street or branch number was entered, and there was a hint with the possibility of choosing this branch.

I've made such a template to play around with the new mail api, and at the beginning, connect.
https://jsfiddle.net/lilandre/ao5L42g1/2/

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Working with Pochta Api</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="script.js"></script>	
</head>
<body>
  <div id="text_test">
    


  </div>

</body>
</html>


$(function(){
  var $texts=$('#text_test');
  $.ajax({
      type: "GET",
      url: "https://api.novaposhta.ua/json",
      "modelName": "Address",
      "calledMethod": "searchSettlements",
      "methodProperties": {
      "CityName": "ки",
      "Limit": 555
    },
    "apiKey": "f11a8e14401ddcf710f7195b4ebe358c",
  success: function(texts){
    $.each(texts, function(i, text){
      $.orders.append('<li> Город или село:'+text.SettlementTypeCode+',Название:'+text.MainDescription+'</li>');
    });
  }
  });

})

This thing doesn't work. Returns - Failed to load https://api.novaposhta.ua/json : No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Negwereth, 2017-10-09
@lilandre

Here is the answer right in the error - CORS is not enabled.
It says right on the page:

Entry points:
JSON - https://api.novaposhta.ua/v2.0/json/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question