Free Spider and array
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
xinyiman · 2015-05-29 13:12
hello guys, I have to create a cgi with free spider and Lazarus. I
need to figure out how to move from html / javascript array that my
cgi must then prepare. for example with the following code to create
an array of three elements and try to send it to my cgi. How do I read
this data from a cgi free spider? thanks
Code: [Select]
Test tabelloni
----------------------------------------------------------------------
motaz · 2015-05-29 15:42
I have no experience on Ajax, but I have experience with FreeSpider,
so that I could help in two cases:
1. If you write a sample of server side in other language, such as PHP
or Java, I could give you FreeSpider version of it
2. If you remove Ajax temporary and replace it with normal form fields
----------------------------------------------------------------------
xinyiman · 2015-05-29 18:50
The problem is that I need to understand how to read the array passed
as POST on free pascal.
----------------------------------------------------------------------
xinyiman · 2015-05-29 18:53
Quote from: motaz on May 29, 2015, 05:42:52 pmI have no experience on
Ajax, but I have experience with FreeSpider, so that I could help in
two cases:
1. If you write a sample of server side in other language, such as PHP
or Java, I could give you FreeSpider version of it
2. If you remove Ajax temporary and replace it with normal form fields
But then the php you know him?
You can not do a simple example to switch from a free php pascal
array. Any one, an array of strings for example. I have to figure out
how to do it. thanks
----------------------------------------------------------------------
nomorelogic · 2015-05-29 20:39
Quote from: xinyiman on May 29, 2015, 08:50:49 pmThe problem is that I
need to understand how to read the array passed as POST on free
pascal.
I never used freespider, btw, a (post) web request should be readable
using a method called like, e.g., "QueryFields".
Can you post the web request here?
----------------------------------------------------------------------
motaz · 2015-05-29 20:44
you can use Request.ContentFields to read posted data
----------------------------------------------------------------------
motaz · 2015-05-30 04:56
You can pass array in one field such as using textarea, or by using
text fields/hidden fields with the same name. Then you can receive
them using request.ContentFields property.
----------------------------------------------------------------------
xinyiman · 2015-06-01 15:46
Ok, I made progress. My javascript code is:
Code: [Select] function ElaboraTabellone()
{
//var Nomi=["hi","caio","sempronio"];
var info = [];
info[0] = 'hi';
info[1] = 'hello';
info[2] = 'pippo';
$.ajax({
url: 'cgi-bin/Tabelloni',
type: 'POST',
dataType: "html",
//dataType: "json",
data: {
numero_atleti: 3,
arrayNomi: JSON.stringify({
lunghezza: info.length, valori: info })
},
success: function (response)
{
$('#mytable').html(response);
},
error: function(XMLHttpRequest,
textStatus, exception) { alert("Ajax failure\n" + errortext); },
async: true
});
}
Lazarus is my code:
Code: [Select]procedure TDataModule1.SpiderCGI1Request(Sender:
TObject;
Request: TSpiderRequest; var Response: TSpiderResponse);
var
Num_Atleti: string;
i: integer;
begin
//Qui inizia il codice del mio programma
//leggo i miei parametri
Num_Atleti:=Request.Form('numero_atleti');
Response.Add('Num atleti: ' + Num_Atleti + '
');
Response.Add('1. ' +
Request.ContentFields.values['arrayNomi[]']);
Response.Add('2. ' +
Request.ContentFields.values['arrayNomi[]']);
for i:=0 to Request.ContentFields.Count-1 do
begin
Response.Add(Request.ContentFields.Strings[i]);
end;
Response.Add('Fine' + '
');
end;
My result on browser
Num atleti: 3
1. 2. numero_atleti=3
arrayNomi={"lunghezza":3,"valori":["hi","hello","pippo"]} Fine
Now I want to understand how I can read data
valori":["hi","hello","pippo"]
who tells me how to do?
Thanks
----------------------------------------------------------------------
motaz · 2015-06-02 10:05
This is an example of how to read data from array in FreeSpider:
Code: [Select]procedure TDataModule1.SpiderCGI1Request(Sender:
TObject;
Request: TSpiderRequest; var Response: TSpiderResponse);
var
i: Integer;
begin
response.Add('You have sent:
');
for i:= 0 to request.ContentFields.Count - 1 do
response.Add(request.ContentFields.Names[i] + ':' +
Request.ContentFields.ValueFromIndex[i] + '
');
response.Add('
');
response.Add('');
end;