Question

Actually i'm developing a timetable selector. Well now i'mt trying to send the values to the miscrosoft sql server database. I'm using mootools, and i'm doing a request as Ajax to pass all values from javascript to php. My problem is that if i send each value individually, it is very slow. So i'm trying to send every values in a javascript object.

var myRequest = new Request.HTML({
        url: "index.php?pagina=2087&",
        method: "post", 
        data: 'transfer='+artigos_sessao,
        onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
         <?php saveData(); ?>
        },
      }).send();  

artigos_sessao is my object with this format {'key':{'id':value,'sessao':value},...}.

And in PHP side i'm doing this

$array= $_POST['transfer'];
echo $array;

But always my $array variable is empty.

What i'm doing wrong?

Thanks.

Was it helpful?

Solution

You can pass a object into the data field of the Request. So my suggestion is to remove parameters from the url and just pass everything as a object in the data:

var myRequest = new Request.HTML({
    url: "index.php",
    method: "post",
    data: {
        'pagina': 2087,
        'transfer': artigos_sessao
    },
    onSuccess: function (responseTree, responseElements, responseHTML, responseJavaScript) {
        <? php saveData(); ?> // this code is not in your question, i supose you have javascript here hopefully :)
    },
}).send();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top