Default Content type on Ajax function


#1

The built in Ajax function is doing a content type of application/x-www-form-urlencoding which is technically incorrect. My web server is very strict on this and therefore I have had to create my own ajax function (using the Options feature is too difficult).

I think the default content type should be application/json or at a minimum if you pass in a body/content it should switch to application/json.


#2

AppStudio’s Ajax function is simply a wrapper for the widely used jQuery Ajax function:

https://api.jquery.com/jquery.ajax/

Here is what the docs say about this:

contentType (default: ‘application/x-www-form-urlencoded; charset=UTF-8’)
Type: Boolean or String
When sending data to the server, use this content type. Default is “application/x-www-form-urlencoded; charset=UTF-8”, which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). As of jQuery 1.6 you can pass false to tell jQuery to not set any content type header. Note: The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger the browser to send a preflight OPTIONS request to the server.


#3

I too am having problems with Ajax php and my new web server (old server company taken over by new company).
I receive an error when issuing the command Ajax(“ajaxGetGloURL.php/?urlToGet=” & encodeURIComponent(myurl)) where myurl="http://www.jumpscore.com.au/63765DrawGeo.txt”

The error is:
"

403 Forbidden

Forbidden

You don't have permission to access /63765DrawGeo.txt on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

I have changed permissions for folders and files but still doesn’t work. Everything worked with the old server. PHP version and settings are the same as old server. New server support don’t seem to know what is wrong.

Any help/suggestions with this would be greatly appreciated.


#4

Maybe you need set some other ajax options.
Here some sample code to set ajax options

  JavaScript 
  var ajaxOptions = {
  "headers" : {"Authorization":  token},
  "contentType" : "application/json",
  "dataType": "json",
  "complete": completeCallback,
  "type": "GET"
  }
  End JavaScript

  req=Ajax(url, ajaxOptions)