Hi all,
For a few weeks now I've been struggling to pass a base64 string to a Mendix POST REST service in JQuery. I've looked at many sources for help on this, and although progress has been made, I just keep end up getting stuck. You can imagine my frustrations.
Here is the most refined version of the code I'm using to send the information:
$.ajax({
type: 'POST',
contentType: 'application/json',
url: 'http://localhost:8080/rest/postdata/',
data: {
title:'Test from AJAX',
file:base64Str,
},
dataType: 'text',
success: function(data, status){
alert(data);
return false;
}
}).fail(function(){
alert('failed');
});
NOTE: base64Str is a variable that holds a file encoded in base64.
The .fail function is being invoked when the AjAX call returns. The error I'm receiving in the Browser Console is: XMLHttpRequest cannot load http://localhost:8080/rest/postdata/. Response for preflight has invalid HTTP status code 405.
I've tried researching this error but to no avail. Has anyone ever seen this error, or knows of a way to fix it? I'll appreciate any leads I can get on this. Thanks!
There are other questions I've asked on the forum throughout my journey on this.
- The answer to my initial post indicated that the base64 string cannot be passed on the URL because of its size. So, I should use a JSON payload to pass that in. This I haven't been able to accomplish to date.
- My second post spoke specifically to the JSON payload. I was pointed to this post on StackOverflow as a reference. I then searched for the JQuery equivalent and landed here; I'm here to this day. I've tried implementing what I've gathered from both posts, but alas, without luck.
I really need help here!