neoajax - Forum

Forum Navigation
You need to log in to create posts and topics.

neoajax

I would like to get an array of the content of the server directory, I have to tried without seeing a result with both

neoAjaxLoad "http://localhost/diapo/test.php" "json" "succes" "erreur"
neoAjaxSend "http://localhost/diapo/test.php" "POST" "[fichiers]" "json" "succes" "erreur"

on subroutine I just get for the moment a consolelog of [data]

<?php
$upload_dir = 'uploads'.DIRECTORY_SEPARATOR;

$b = scandir($upload_dir,1);
print_r($b);
echo {$b};

?>

can you help me on how to proceed (I looked at the examples but I can't find a real match)

@phil78 if you use neoAjaxLoad to get JSON data you must be sure your PHP script returns JSON data. Try this:

<?php
$upload_dir = 'uploads'.DIRECTORY_SEPARATOR;
$b = scandir($upload_dir,1);
echo json_encode($b);
?>

 

 

thank you @luishp I have checked with the parameter 'text' it is ok, and with the parameter 'json' I need json_encode($b) indeed. 

But what was wrong was the path of the file neoAjaxLoad "http://localhost/test.php" "text" "succes" "erreur".

Which is curious is when I use wamp as php server I have a cors error even if I add header("Access-Control-Allow-Origin: *"); inside test.php.

But with neophp server it works well.

@phil78 in the case of WAMP, you can add the Access-Control-Allow-Origin header to the Apache server configuration file (httpd.conf) or the .htaccess file in the root directory of your project. Here's an example of how to allow cross-origin requests from all domains in the .htaccess file:

Header set Access-Control-Allow-Origin "*"

After adding this line to your .htaccess file, restart your Apache server and try making the request again. The Access-Control-Allow-Origin header should now be included in the response, and you should no longer encounter the CORS error.

Hope it helps.

thanks a lot @luishp Last question, I think I'm not very good but I can't assign the array of parameter [resp] in my variable.
here is what [resp] contains.

best regards

Uploaded files:
  • You need to login to have access to uploads.

@phil78 have you tried using with ParseJSON command?
Not sure but it seems like a string not a parsed JSON.

Hello @luishp Yes I have tried also with the same result. Really I don't understand how to manage the return value.

If I try to debug and request $Apps.tempo it is unknown, if I request $Apps.annees, I get an empty array, but with consoletable I get the result sent before which is not exclusively the content of responseText !

CreateEmptyObject [tempo]
SetVar [tempo] [resp]

SetVar [annees] [tempo.responseText]
consoletable [annees]

@phil78 note that it's not $Apps but $App.
Anyway I can't help very much without access to the code and see what's happening exactly by myself.

In my investigations, when a variable responseText contains a string like:

["1967", "1968", "1969"]

then this line of script:

ParseJSON [responseText] [myresultobject]

is clever enough to parse the string into an object, even though it is not json encoded with curly braces.

I don't know if that is of any help here?

luishp has reacted to this post.
luishp

Thanks to @luishp and @susan.  My aplogies, By dint of testing between text and json I think I forgot to save the php file after modifying with json_encode which explains why I always saw the same result in consoletable. Now receive the good value and I can populate my array.

I have another question (I hope the last). :

Now I need to populate 2 other arrays but depending from one or two parameters. I try to use neoAjaxLoadEx. Is it the good solution ?

1 : neoAjaxLoadEx "http://localhost/getEvts.php" "[Annee]" "json" "getEvts" "erreur"  ([Annee] is the selection of the first array)

2 : CreateEmptyArray [MyParam]
SetVar [MyParam(0)] [Annee]
SetVar [MyParam(1)] [Evt]

neoAjaxLoadEx "http://localhost/getImages.php" "[MyParam]" "json" "getImages" "erreur"

I think I don't know how to get the value of the parameters in my php file because when I do scandir($dir) $dir is empty.
Here is what I tried:
$dir = $_POST['Annee'];
$dir = $_SERVER['Annee'];
$dir = $_POST['MyParam[0]'];
$subdir = $_POST['MyParam[1]'];

 

@phil78 as you don't want to send headers, and you want to send some parameters you should use neoAjaxSend and an Object, not an Array.

CreateEmptyObject [myparam]
SetVar [myparam.Annee] [Annee]
SetVar [myparam.Evt] [Evt]
neoAjaxSend "http://localhost/getImages.php" "POST" "[myparam]" "json" "getImages" "erreur"

Server side:

$Annee = $_POST['Annee'];
$Evt = $_POST['Evt'];

I hope it helps.

farhad2008, Phil78 and susan have reacted to this post.
farhad2008Phil78susan
Quote from luishp on February 19, 2023, 7:06 pm

@phil78 in the case of WAMP, you can add the Access-Control-Allow-Origin header to the Apache server configuration file (httpd.conf) or the .htaccess file in the root directory of your project. Here's an example of how to allow cross-origin requests from all domains in the .htaccess file:

Header set Access-Control-Allow-Origin "*"

After adding this line to your .htaccess file, restart your Apache server and try making the request again. The Access-Control-Allow-Origin header should now be included in the response, and you should no longer encounter the CORS error.

Hope it helps.

Hi @luishp

When I create the file .htaccess I get this error.

Diapo-Web/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration, referer: http://localhost/

there is also theses lines in httpd.conf, there is no difference if I comment them.

# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ".ht*">
Require all denied
</Files>