AJAX Plugin - "Content-Type" is overridden...or something.

Bugs will be moved here once resolved.

Post » Mon Jan 19, 2015 2:29 pm

Problem Description
The problem is with the AJAX-plugin. It seems calling "setRequestHeader" to change the "Content-Type" of the request doesn't work. It uses the default value of: "application/x-www-form-urlencoded" even if you change it to something else.

When looking at the code in the Plugin it does indeed seems like it should work, I even printed the headers and it seemed correct.

Steps to Reproduce Bug
  • Add AJAX object to Layout
  • In: On Layout Start, set the header: "Content-Type" to Value: "application/json"
  • Make an AJAX request to some server
  • Observe on the server that the Content-Type that is being sent is "application/x-www-form-urlencoded".

Observed Result
As seen above, the request header is overridden by the default one (or not being set at all)

Expected Result
"Content-Type" should be set to "application/json", but isn't.

Solution
Removing the following lines in the runtime.js of the AJAX -plugin (line 218-224), seem to fix this problem:
Code: Select all
if (data_)
{
  if (request["setRequestHeader"])
  {
    request["setRequestHeader"]("Content-Type", "application/x-www-form-urlencoded");
  }
}


Construct 2 Version ID
Release 190 (64-bit)
B
4
Posts: 12
Reputation: 224

Post » Tue Jan 27, 2015 5:29 pm

I made it disable the default application/x-www-form-urlencoded type if you use 'Set request header' to set Content-Type, so should be fixed in the next build.
Scirra Founder
B
402
S
238
G
89
Posts: 24,632
Reputation: 196,031


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests