Hi.
I have a problem with recived JSON data by Jquey. I recive data ba Google apps script, but this no matter.
Data is sensed (by test) from html file from my local computer and recived by Google script.
Code of my html.
- <!DOCTYPE html>
- <html lang='pl'>
- <head>
- <meta charset='utf-8'>
- </head>
- <body>
- <div onclick ="A1()"> TEST </div>
- </body>
- <script
- src="http://code.jquery.com/jquery-3.3.1.js"
- integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
- crossorigin="anonymous"></script>
- <script type="application/javascript">
- $.ajaxSetup({
- url: "https://script.google.com/macros/s/***//exec",
- type: "post"
- });
- function A1() {
- var sub_d = [ "a1", 2, "a3" ];
- var d1 = { test1 : "pass1" };
- var d2 = { test1: sub_d };
-
- var d3 = JSON.stringify(d1);
- var d4 = JSON.stringify(d2);
- var res = $.ajax (
- {
- data: d4,
- beforeSend: function() { alert(d2); }
- });
-
- res.done(function (odpserv, textStatus, jqXHR) {
- console.log(odpserv);
- console.log(textStatus);
- console.log(jqXHR);
- });
- }
- </script>
Google code.gs
- function doPost(e){
- var ERrrS, ES;
- try {
- var SS = SpreadsheetApp.openById('****');
- var sh = SS.getSheetByName('A');
-
- sh.appendRow([ e, e.parameter])
-
- ES= "OK";
-
- }
- catch (err) {
- ES = err;
- }
First problem
I don't know whay recived data JSON looks
{parameter={test1=pass1}, contextPath=, contentLength=11, queryString=, parameters={test1=[Ljava.lang.Object;@4afd9e0c}, postData=FileUpload}
Whay I recive "
parameter=
" or "
contextPath=
" keys in data. Look code above. Anywher I don't add any additional data. So why I recive what I recive?
Second
If I send
var d1 = { test1 : "pass1" }
;
i expect recive
{ test1 : "pass1" }
If I send
d1
virable i recive
{test1=pass1}
in parameter objec. Why I don't recive
{test1 : pass1}
If I send
d3
virable i recive
{{"test1":"pass1"}=}.
Why?
But this is small problem, because I can read data in obj.parameter
Third - Arrays - There I don't understand anything.
Sending d2 I recive
{test1[]=a1}
in e.parameter
Sending d4 I get
{{"test1":["a1",2,"a3"]}=}
It's look as a Key in e.parameter. array
- e= { parameter : [
- {"test1":["a1",2,"a3"]} : =
- ]
- }
Of course I was tried parse (
JSON.parse() ) all recived data (
e), and
e.parametre, but anyway I couldn't read ( in Google script) the AJAX's send data (Array)
Please let my know, what I doing wrong, where I make mistake.