Illegal type: string, expected: JSON
-
I was using
.callWithPOST
this way before and it worked without any problems:.callWithPOST("mySubURL", "", var callback)
But with the current HISE build I get
Illegal type: string, expected: JSON
I am not an expert, how to overcome this?
-
Checkout the documentation here:
https://docs.hise.audio/scripting/scripting-api/server/index.html#callwithpostServer.setBaseURL("http://hise.audio"); const var p = { "first_argument": 9000 }; // This dummy file just returns the `first_argument` as `post_argument`... Server.callWithPOST("post_test.php", p, function(status, response) { Console.print(response.post_argument); });
Argument one needs to be a string for the URL.
Argument two needs to be a JSON object. In the example it is called p, and we can see that p has been setup as a const var, with an array of key+value pairs. In the example there is just one called 'first_argument' with the value of 9000. But you could have any amount of pairs there.Argument three for the actual call is a function. You can write them out (usually) in one of two ways. The first is how the example shows it, where the function is not declared as its own const object and is just declared right within the input arguments for callWithPOST.
This is called an anonymous function.
But you could also tie that function to its own declaration, like this:
Server.setBaseURL("http://hise.audio"); const var p = { "first_argument": 9000 }; // This dummy file just returns the `first_argument` as `post_argument`... Server.callWithPOST("post_test.php", p, print_response); inline function print_response(status, response) { Console.print(response.post_argument); }
The benefit of doing it this way is that you can organise your code into namespaces, or even just separate javascript files, that collect together related functions.
-
@Orvillain Wow Thank you very much for this detailed explanation! I am grateful to you :folded_hands: