0

I'm trying to send a request using Jquery using the Redmine API, which says it has support for jsonp.

So, i tried differents ways to make request with Jquery and i already search for the 'mime type' errors and try to solve using the answers but the throw error in the console is evertime the same (Google Chrome):

refused to execute script from 'http://redmine_domain_sample/users/current.json?callback=jQuery21309665620597314108_1508906065651&_=1508906065652' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

And in the Firefox:

SyntaxError: missing ; before statement

apponiting to the json that really returns my data. when i click i can see the data:

enter image description here

This is my code:

$("#redmine").click(function() { $.ajax({ type:"get", url:"http://redmine_domain_sample/users/current.json", dataType: "jsonp", contentType: "application/javascript", success: function(response) { alert(response.firstname); exibeProjetosRedmine(); } }); });

This url make an authentication request, which works, so when i input the login data, the errors on top appears.

If i make this request from an extension client , for example, the chrome Advanced REST Client, it works, but in my localhost Laravel application doesnt.

The request return 200 ok, but the Jquery request dont goes to the success function. I really even tried some solutions when i searching like:

  • add some headers
  • pass format=json in url

but dont work. What i'm doing wrong? I believe that is a simple error but i really not understand yet. Thanks.

Isaac Gomes
  • 410
  • 1
  • 6
  • 15
  • This sounds like a server issue (apache, ngnix), not an Redmine issue... Take a look here:https://stackoverflow.com/questions/24528211/chrome-refuses-to-execute-an-ajax-script-due-to-wrong-mime-type – Aleksandar Pavić Oct 25 '17 at 09:23
  • this doesn't work if you're trying to use an external API like me – Isaac Gomes Oct 25 '17 at 14:16
  • Server should return `application/javascript` as content type. [Link](https://stackoverflow.com/questions/111302/best-content-type-to-serve-jsonp) – abdul-wahab Nov 24 '17 at 13:48

2 Answers2

1

Thanks all. But i solved the problem just with communication. Redmine API accepts jsonp, but this is, by default, disabled. So, i can't make request with jsonp if the domain don't allows that. No way.

Happily, i meet the redmine domain admin that i tried to access. And i asked for allows that in the administration config (docs say that) allowed jsonp. And he's made it and i solved my problem.

Isaac Gomes
  • 410
  • 1
  • 6
  • 15
0

The fact that it works fine with the Chrome REST client already point to a problem with the JavaScript code rather than a problem with the Redmine API.

When getting the error in Firefox console did you check with the Debugger which line of code it is pointing to? Maybe the error is in some other JS Code in that file...

GET requests typically even work quite fine for me without putting dataType and contentType. With an error function you could go into more debugging what is going wrong.

How about trying something like this (the '.json' extension already tells Redmine what format you want to get back):

$.ajax({
  url: "http://redmine_domain_sample/users/current.json",
  type: "GET",
  error: function(jqXHR, textStatus, errorThrown) {
    if (jqXHR.status == 200) {
      alert(textStatus);
      alert(errorThrown);
    } else {
      alert(textStatus);
      alert(errorThrown);
    }
  },
  success: function(response, textStatus, jqXHR) {
    alert(response.firstname);
    exibeProjetosRedmine();
  }
});
Stephan Wiehr
  • 166
  • 1
  • 7