That is how I generally make calls.. ie;
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
However this is a new world and when using pre-done libraries, outside
contractors or creating a client API, using
'request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");' is not always possible.
A lot of things RESTful seem to use application/json.
On 9/8/2016 12:22 PM, Neil Gunton wrote:
Donavon wrote:
If I use Embperl to receive JSON data. That's where the issue
arises. <script> |
var formData = {"data1":a,"data2":b,"data3":c};
$.ajax(
{dataType:"json",
contentType:"application/json; charset=UTF-8",
url:'/folder1/doSomething1.epl',
data:formData, success:function(response){ CurrentArray=response; } });
</script>
Ok, so it sounds like you have some control over how the calls are
happening on the client side, is that correct? I don't use JQuery
myself, but fwiw here is roughly how I make an Ajax call using JSON
data. I use a function createRequest that just wraps creating a new
XMLHttpRequest (as well as picking up some exceptions to do with
Microsoft etc - not really important here).
var data = {a: 1, b: 2, c: 3};
var params = 'data=' + encodeURIComponent (JSON.stringify (data));
createRequest();
if (request != null)
{
var url = '/ajax/some_handler.html';
request.open("POST", url, true);
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.onreadystatechange = the_callback_function;
var result = request.send (params);
}
So I dunno if it's relevant, but I don't use "application/json" as the
content type, but rather "application/x-www-form-urlencoded". On the
server side, I use a .html page, but that could be anything you set up
to be handled by Embperl in your Apache config. It doesn't have to
actually produce html code, obviously, it could respond entirely in
JSON or XML or whatever you want to set. But that's not really
relevant - the important thing is that I am able to receive the call
just fine, and it contains the JSON data in a form field called 'data'
(arbitrary name, obviously, whatever you want to call it). I access it
via %fdat as usual.
So, if you are in control of how the call happens from the client
side, then it seems to me there's no reason why you can't pass JSON to
Embperl, and there's no reason why it has to be "application/json".
Like I said I dunno if the content type is the issue, but just a demo
of a method that I use, that works fine.
Hope that helps,
Neil
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscr...@perl.apache.org
For additional commands, e-mail: embperl-h...@perl.apache.org