DuduzinCp Posted December 12, 2022 Share Posted December 12, 2022 (edited) 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) Edited December 12, 2022 by DuduzinCp Link to comment
DuduzinCp Posted December 12, 2022 Author Share Posted December 12, 2022 To be more specific, I'm having problems in php, because I don't know how to make php send this JSON to mta, I think it's incorrect to use 'echo' in php Link to comment
Scripting Moderators Sarrum Posted December 12, 2022 Scripting Moderators Share Posted December 12, 2022 . You can access the field using $_POST["verifyUserAccessTOJSON"] 1 Link to comment
DuduzinCp Posted December 12, 2022 Author Share Posted December 12, 2022 (edited) . 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 December 12, 2022 by DuduzinCp Link to comment
Shady1 Posted December 12, 2022 Share Posted December 12, 2022 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 1 Link to comment
DuduzinCp Posted December 12, 2022 Author Share Posted December 12, 2022 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 Link to comment
Shady1 Posted December 12, 2022 Share Posted December 12, 2022 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/ 1 Link to comment
Overkillz Posted December 12, 2022 Share Posted December 12, 2022 (edited) 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 December 12, 2022 by Overkillz 1 Link to comment
DuduzinCp Posted December 12, 2022 Author Share Posted December 12, 2022 (edited) 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 December 12, 2022 by DuduzinCp Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now