Jump to content

FetchRemote API does not return any value


DuduzinCp

Recommended Posts

    • Can anyone help me with this problem? I made an API in php and it returns a JSON but it is not returning any result only in MTA.
       
      function test (url)
         sendOptions = {
            formFields = {
               verifyUserAccessTOJSON = toJSON( {busca = '1' })
            },
         }
         fetchRemote ( url, sendOptions, notificationCallback )
      end
      function notificationCallback(data, info)
         test = fromJSON(data)
         print(inspect(data))
         print(inspect(info))
      end
      test('noLinkForSecurity')

      In PHP, okay, it returns a

      echo json_encode($dados);

      This that appears in the debug (nothing)

      image.png

Edited by DuduzinCp
Link to comment
  • DuduzinCp changed the title to FetchRemote API does not return any value
 

?. You can access the field using

$_POST["verifyUserAccessTOJSON"]

Yes but I'm not looking for how to access the file, I'm looking for how to send the JSON as a response

<?php
    header('Content-type: application/json; charset=utf-8');
    $dadosEnviados = file_get_contents('php://input');
    $dadosEnviados = json_decode($dadosEnviados, true);

    $connPdo = new PDO('db');

    if (isset($dadosEnviados['busca'])) {
        (int)$busca = $dadosEnviados['busca'];
        $sql = $connPdo->prepare("SELECT * FROM licenses WHERE ID = ?");
        $sql->bindParam(1, $busca);
    }

    $dados = [
        'result' => false,
        'valores' => []
    ];

    if ($sql->execute()) {
        if ($sql->rowCount() > 0) {
            $dados['result'] = true;
            $dados['valores'] = $sql->fetchAll();
        }
    }

    echo json_encode($dados);

My php

Edited by DuduzinCp
Link to comment
function test (url)
   sendOptions = {
      formFields = {
         verifyUserAccessTOJSON = toJSON( {busca = '1' })
      },
   }
   fetchRemote ( url, sendOptions, notificationCallback )
end
function notificationCallback(data, info)
   test = fromJSON("["..data.."]")
   outputDebugString(test)
end
test('noLinkForSecurity')

hi you should test this code and let me know if you have any problem on debug side,I don't understand exactly what you want

  • Thanks 1
Link to comment
 
function test (url)
   sendOptions = {
      formFields = {
         verifyUserAccessTOJSON = toJSON( {busca = '1' })
      },
   }
   fetchRemote ( url, sendOptions, notificationCallback )
end
function notificationCallback(data, info)
   test = fromJSON("["..data.."]")
   outputDebugString(test)
end
test('noLinkForSecurity')

hi you should test this code and let me know if you have any problem on debug side,I don't understand exactly what you want

image.png

Link to comment
 

i suggest you to use mta sdk for this project, + you used sql codes, put them on Lua side.

http://code.opencoding.net/mta/mtaphpsdk_0.4.zip

[TUT] https://forum.multitheftauto.com/topic/32557-tut-php-sdk/

Many of the times we don't need to use MTA SDK.

Otherwise, he is trying to build an api, so, it useless to use MTA SQL connector in this case aswell ..

--------------------------------------------------------

Well, I have done some researches about the issue its in php file. You are not receiveing a JSON, so, the decoding function won't never work.

 If you directly output the content, you probably are going to get something un-parsed which is related with 'WebKitFormBoundary' or similar.

There are methods made by people to parse it and try to get a json content, but, it doesn't support weird content.

Regards.

Edited by Overkillz
  • Thanks 1
Link to comment

 

 

Many of the times we don't need to use MTA SDK.

Otherwise, he is trying to build an api, so, it useless to use MTA SQL connector in this case aswell ..

--------------------------------------------------------

Well, I have done some researches about the issue its in php file. You are not receiveing a JSON, so, the decoding function won't never work.

 If you directly output the content, you probably are going to get something un-parsed which is related with 'WebKitFormBoundary' or similar.

There are methods made by people to parse it and try to get a json content, but, it doesn't support weird content.

Regards.

I tested the api code and the same lua file and it worked, it must be my hosting's php configuration

Edited by DuduzinCp
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...