Page 1 of 2

How receive data from a php script

Posted: Sat Aug 30, 2014 1:05 am
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.

Re: How receive data from a php script

Posted: Sat Aug 30, 2014 8:06 am
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

Re: How receive data from a php script

Posted: Sun Aug 31, 2014 8:15 pm
by falsam
I can use Json with Pure Basic but not with SpiderBasic.

Re: How receive data from a php script

Posted: Mon Sep 01, 2014 12:15 pm
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.

Re: How receive data from a php script

Posted: Mon Sep 01, 2014 2:06 pm
by poshu
Json is implemented since beta 1.

Re: How receive data from a php script

Posted: Mon Sep 01, 2014 4:12 pm
by falsam
poshu wrote:Json is implemented since beta 1.
Yes but but how does it work with Spider Basic ?

Re: How receive data from a php script

Posted: Tue Sep 02, 2014 3:04 pm
by poshu
Like in pure : loadjson()?

Re: How receive data from a php script

Posted: Tue Sep 02, 2014 5:24 pm
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

Re: How receive data from a php script

Posted: Tue Sep 02, 2014 7:00 pm
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?

Re: How receive data from a php script

Posted: Tue Sep 02, 2014 7:06 pm
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