How receive data from a php script

Just starting out? Need help? Post your questions and find answers here.
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

How receive data from a php script

Post by falsam »

■ i have this very small script php (receivedata.php)

Code: Select all

<?php
    echo json_encode(array("value" => "Hello World"));
?>
■ And now, my very small spiderbasic code

Code: Select all

rocedure.s Dummy()  
  !var cr=""
  
  !$.getJSON('receivedata.php', function(Data) {
  ! cr = Data.value;
  ! alert(cr); ; //Data receive is correct
  !});
  
  !return cr;
EndProcedure

Debug Dummy()
the alert function returns the value of the scrip php. But not debug. How can I get this value?

PS : The JavaScript is slow to execute.
Last edited by falsam on Sat Oct 22, 2016 11:24 pm, edited 1 time in total.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
the.weavster
Posts: 222
Joined: Sat Mar 01, 2014 3:02 pm

Re: How receive data from a php script

Post by the.weavster »

There are now JSON commands so you shouldn't have to resort to inline JavaScript: http://purebasic.com/documentation/json/index.html
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: How receive data from a php script

Post by falsam »

I can use Json with Pure Basic but not with SpiderBasic.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
the.weavster
Posts: 222
Joined: Sat Mar 01, 2014 3:02 pm

Re: How receive data from a php script

Post by the.weavster »

falsam wrote:I can use Json with Pure Basic but not with SpiderBasic.
Ah, I didn't realise these commands hadn't been implemented in SpiderBasic yet.
poshu
Posts: 96
Joined: Mon Feb 24, 2014 11:46 pm

Re: How receive data from a php script

Post by poshu »

Json is implemented since beta 1.
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: How receive data from a php script

Post by falsam »

poshu wrote:Json is implemented since beta 1.
Yes but but how does it work with Spider Basic ?

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
poshu
Posts: 96
Joined: Mon Feb 24, 2014 11:46 pm

Re: How receive data from a php script

Post by poshu »

Like in pure : loadjson()?
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How receive data from a php script

Post by Peter »

poshu wrote:Like in pure : loadjson()?
Did you try it? It doesn't work.

Works:

Code: Select all

Procedure HttpGetEvent(Success, Result$)
  If Success
    Debug Result$ ; -> {"value":"Hello World"}
  Else
    Debug "HTTPRequest(): Error"
  EndIf
EndProcedure

HTTPRequest(#PB_HTTP_Get, "http://localhost/sb/php.php", "", @HttpGetEvent())
Doesn't work:

Code: Select all

Result = LoadJSON(#PB_Any, "http://localhost/sb/php.php")
Debug Result ; -> 100000
Debug ComposeJSON(Result, #PB_JSON_PrettyPrint) ; -> undefined
I guess, we need a callback (like in HTTPRequest()) for LoadJSON().

Greetings ... Peter
the.weavster
Posts: 222
Joined: Sat Mar 01, 2014 3:02 pm

Re: How receive data from a php script

Post by the.weavster »

Peter wrote:Works:

Code: Select all

Procedure HttpGetEvent(Success, Result$)
  If Success
    Debug Result$ ; -> {"value":"Hello World"}
  Else
    Debug "HTTPRequest(): Error"
  EndIf
EndProcedure

HTTPRequest(#PB_HTTP_Get, "http://localhost/sb/php.php", "", @HttpGetEvent())
Doesn't work:

Code: Select all

Result = LoadJSON(#PB_Any, "http://localhost/sb/php.php")
Debug Result ; -> 100000
Debug ComposeJSON(Result, #PB_JSON_PrettyPrint) ; -> undefined
I guess, we need a callback (like in HTTPRequest()) for LoadJSON().

Greetings ... Peter
Have you tried HTTPRequest() and then using ParseJSON() on the response?
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How receive data from a php script

Post by Peter »

ParseJSON() works. What i try to explain is, that it is (currently) not
possible to receive data from a php script with the JSON-Commands.

Greetings ... Peter
Post Reply