2

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.

2
  • still not working. $_POST['transfer'] doesn't exist at $_POST array Commented Mar 27, 2014 at 15:10
  • 1
    Luis, the data field takes a object. You could do data: { 'pagina': 2087, 'transfer': artigos_sessao }, Commented Mar 27, 2014 at 15:45

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

saveData() is a function where i receive the array. function saveData(){ $array= $_POST['transfer']; echo 'console.log("'.echo $array;.'");"; } But no results... :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.