post data to PHP and get response

Hi, i try to post two variables to my php and then get response as json. I can`t find any WORKING example. Some body can help me how can i do it ? Is it possible ?

Hi there! Fuse doesn’t care about what kind of server setup you choose to use, as long as it has standard endpoints to communicate with. See https://www.fusetools.com/docs/fusejs/http for more details.

Cool, and in

body: JSON.stringify(requestObject)

i send some array right ?

guys, i have this code :

<App>
    <JavaScript>
        var o = require("FuseJS/Observable");
            var uri = "http://brandlabstudio.pl/cod";
        var sendRequest = function() {
            var options = {
                method: 'POST',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                             },
                body: {
                    s_api: 's_hFAaJzszSqGMnzizAjE3',
                    c_api: 'c_hsMMTJXs1pe5s17Yu378',
                }
            };
            fetch(uri, options).then(function(response) {
                var data = JSON.stringify(response)
                debug_log(data);
            }, function(error) {
                debug_log(error);
            });
        };

        module.exports = {
          send: sendRequest,
        };
    </JavaScript>
    <StackPanel>
        <TopFrameBackground />
        
        <Button Text="Send" Clicked="{send}" />
    </StackPanel>
</App>

but something is wrong. I dont have any response :confused: just this

LOG: Fuse.Scripting.V8.Object 

You have to JSON.stringify() the contents of your request body.

like this ? :

<App>
    <JavaScript>
        var o = require("FuseJS/Observable");
            var uri = "http://brandlabstudio.pl/cod";
        var sendRequest = function() {
            var options = {
                method: 'POST',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                             },
                body: JSON.stringify({
                    s_api: 's_hFAaJzszSqGMnzizAjE3',
                    c_api: 'c_hsMMTJXs1pe5s17Yu378',
                })
            };
            fetch(uri, options).then(function(response) {
                var data = JSON.stringify(response)
                debug_log(data);
            }, function(error) {
                debug_log(error);
            });
        };

        module.exports = {
          send: sendRequest,
        };
    </JavaScript>





    <StackPanel>
        <TopFrameBackground />
        
        <Button Text="Send" Clicked="{send}" />
    </StackPanel>
</App>

is it any way to Check what is sended ?

Yes, that should make sure you actually send a valid request. (I tested it myself and then got a sensible reply).

However, I don’t know enough about JS to say for sure but your promise handling looks a bit strange to me. I do however know that this works for sure. You can also find a link to the full fetch documentation there (it’s a standard JS-thing and not something Fuse-specific :slight_smile: ).

Can you send me source how you test it ?

There’s no other code to share. I didn’t do anything else than take your code, make sure the body was actually serialized to a string and then see that you got some sort of response.

The links in my previous post shows how you use fetch.

Thank you buddy.

Finaly i did it, for people who have same problem, i just install rest server based on codeigniter. And it working awesome.

link : https://github.com/chriskacerguis/codeigniter-restserver