D
D
Dmitry Antonov2015-07-08 03:15:17
JavaScript
Dmitry Antonov, 2015-07-08 03:15:17

How to fix error on ajax request using jsonp?

I'm trying to get json from a third-party site ... but it gives an error, although I see in the console that I received json.
Generally ajax request is

jQuery.ajax({
  url: 'https://www.oplata.info/asp2/price_options.asp',
  type: 'GET',
  dataType: 'jsonp',
  data: {'p': id, 'n': 1, 'c': 'WMR'},
  success: function(data) {
   $('#cena').html(data.price);
  }
});

as a result, I don’t get any data, but I see this error.
81321079d5d84a0fb2bb99d0f3634e1b.jpg
571758d655524ed2bb92cc347b04ad1d.jpg

If I try through crossDomain
jQuery.ajax({
  url: 'https://www.oplata.info/asp2/price_options.asp',
  type: 'GET',
  dataType: 'json',
  data: {'p': id, 'n': 1, 'c': 'WMR'},
  crossDomain: true,
  success: function(data) {
   $('#cena').html(data.price);
  }
});

It gives out like this
6d664fc1980449dea72061525e399d56.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Melnikov, 2015-07-08
@mlnkv

in response to a jsonp request, non-json data should be returned, read how jsonp works
(well, more precisely, not just json)
https://ru.wikipedia.org/wiki/JSONP
you need to either correctly implement jsonp (checking for the get callback parameter)
or add on the server when sending data the header Access-Control-Allow-Origin
habrahabr.ru/post/114432

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question