Error picking JSON from text - JQUERY

Asked

Viewed 145 times

0

I’m rescuing a json of a text, however, the following error occurs:

XMLHttpRequest cannot load http://www.vagas.com.br/vagas/feeds.js?q=engenheiro. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://aerc.postali.com.br' is therefore not allowed access. The response had HTTP status code 503.

follows below the url:

http://www.vagas.com.br/vagas/feeds.js?q=engenheiro

            $.ajax({
            url: "http://www.vagas.com.br/vagas/feeds.js?q=engenheiro",
            type: "GET",
            dataType: "html",
            success: function (data) {

            }
            });

Thank you.

  • What do you want to pick up specifically? you can use indexof to take the Dice that starts the string and then the Dice that ends the string and make a substring... and why take from this unorganized file?

  • @Gabrielrodrigues I managed to catch the json, so I can think of the following error: Xmlhttprequest cannot load http://cors.io/? u=http://www.vagas.com.br/vagas/feeds.js?q=engenheiro. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://aerc.postali.com.br' is therefore not allowed access. The Response had HTTP status code 503." I will change the question

  • http://answall.com/questions/64695/no-access-control-allow-origin-header-is-present-on-the-requested-resource

1 answer

3


Look if you have access to this domain. js should be generated by some data source, recommend changing the strategy, however you can do so (if js are in the same domain as the page):

    $.ajax({
        url: "/vagas/feeds.js?q=engenheiro",
        type: "GET",
        dataType: "text",
        success: function (data) {
             eval(data);

             var dados = new Vagas().listaDeVagas;

             console.log(dados);
        }
    });

Obviously eval may cause some headaches, but if you use it with scripts from the same domain as yours and have control over them then you can use it without fearing so much.

I recommend the following reading: Eval is either good or bad?

If you are on a different domain you will need to have control of cross-origin, only if you have access to the source domain of feeds.js, however you can get around the problem using a server-side language.

In case I think it uses C#, I created some time ago a webproxy in C# to solve this type of problem, download the file simple-http-proxy-csharp.ashx in:

And put it on your server, its use is simple:

http://your-domain/folder/simple-http-proxy-csharp.ashx?url=http://urlexeterna/feed.js

I don’t know if you have direct access to ASP.NET-MVC, because I have never used ASP.NET-MVC myself, but I believe it is possible to access the simple-http-proxy-csharp.ashx directly

The use would look something like:

    var url = "http://www.vagas.com.br/vagas/feeds.js?q=engenheiro";
    url = encodeURIcomponent(url);

    $.ajax({
        url: "simple-http-proxy-csharp.ashx?url=" + url,
        type: "GET",
        dataType: "text",
        success: function (data) {
             eval(data);

             var dados = new Vagas().listaDeVagas;

             console.log(dados);
        }
    });

I must inform you again that this is not the best course of action, it would be better to look for another data source requesting from T.I. (IT) of the company that provides the data, something like REST or SOAP, but if they do not have such services then the way is unfortunately to use a "proxy", as I mentioned.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.