Consuming Json, problem with Cors

0

Good morning!

I'm running a query (via jQuery and Json) in the Mercadobitcoin API, but I always get a return error. Upon inspection, there is a failure by the CORS method. I checked the documentation, there is a warning "the methods have CORS". I searched in several places but I still did not find how to resolve the query without needing something from the server side.

API Doc: link

I'm using a simple query like:

$.get( "http://meusite.com/", function( data )

Could someone give me a light?

Hugs.

    
asked by anonymous 06.08.2018 / 16:43

2 answers

0

Here is a functional example (check the console) of using the API: link

According to DOC, the URL is this: https://www.mercadobitcoin.net/api/<coin>/<method>/ , where coin can be BTC , LTC , or BCH ; where method can be ticker , orderbook or trades     

06.08.2018 / 19:04
0
If the methods have CORS enabled in server side a small change in your AJAX request can solve everything, you must add the line crossDomain: true in the header of your request.

Here is an example of an ajax request using CORS true in the header:

$.ajax({
        url: "http://meusite.com/",
        type: "GET",
        crossDomain: true, 
        dataType: "json",
        success: function (response) {
            var resp = JSON.parse(response)
            alert(resp.status);
        },
        error: function (xhr, status) {
            alert("error");
        }
    });
    
06.08.2018 / 19:23