If you have access to the domain that .js should be generated by some data source, I recommend to change the strategy, however you can do so (if js is 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
can cause some headaches, but if you use scripts from the same domain as yours and have control over them then you can use them without fearing so much.
I recommend the following: Is Eval a Good Guy or Bandit?
If you are in a different domain you will need to have control of cross-origin
, this is only if you have access to the feeds.js source domain, however you can work around the problem using a server-side language.
In case I think it uses C#
, I created some time 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 do not know if you have direct access to ASP.NET-MVC because I've never used ASP.NET-MVC myself, but I believe it's possible to access simple-http-proxy-csharp.ashx
directly
The usage 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 have to say again that this is not the best way for this case , it would be better to look for another source of data requesting next to the IT company that provides the data, something like REST or SOAP, but if they do not have such services then the way unfortunately is to use a "proxy", as I mentioned.