HISE Logo Forum
    • Categories
    • Register
    • Login

    Illegal type: string, expected: JSON

    Scheduled Pinned Locked Moved Scripting
    3 Posts 2 Posters 171 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • resonantR
      resonant
      last edited by resonant

      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?

      O 1 Reply Last reply Reply Quote 0
      • O
        Orvillain @resonant
        last edited by

        @resonant

        Checkout the documentation here:
        https://docs.hise.audio/scripting/scripting-api/server/index.html#callwithpost

        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, 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.

        resonantR 1 Reply Last reply Reply Quote 1
        • resonantR
          resonant @Orvillain
          last edited by

          @Orvillain Wow Thank you very much for this detailed explanation! I am grateful to you :folded_hands:

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          11

          Online

          1.7k

          Users

          11.9k

          Topics

          103.6k

          Posts