thomagron
thomagron

Reputation: 101

Use javascript array content in php

I want to use the content of my javascript array in php. i need to add up all content in different groups and put them in a database. my php is better then javascript (dont realy know anyting about it).

my array content is:

["I", "S", "C", "D", "I", "D", "C", "S", "I", "C", "D", "S", "C", "D", "S", "I", "D", "C", "I", "S", "C", "S", "I", "D", "S", "C", "D", "I", "D", "S", "C", "I", "D", "I", "S", "C", "S", "D", "C", "I"]

dont know if you need it but its there.

Is it possible to content to php so i can use it there? Is it even possible becouse php is server and javascript is client.

i heared something about json but cant figure it out.

EDIT

i want to give all results a value. the first item in the array gets '4', the second item '3', third item '2' and fourth item '1', then again, so fifth item '4' sixth item '3' etc...

so u get:

"I" = 4, "S"=3, "C"=2, etc..

then i want to count up all the I's, C's, D's and S's. and put the results in a database.

Upvotes: 0

Views: 39

Answers (1)

peiman F.
peiman F.

Reputation: 1658

Actually this is not a clean way but yes its possible...

1)first you must parse javascript array

2)pass it to php with a ajax request

3)do the process and return the results

this is my sample:

        javaparsedArray = JSON.stringify(javaScriptArray);
        $.ajax({
            type: "POST",
            url: 'php.php',
            data:"action=parsArray&value="+javaparsedArray ,
            cache:'false',
            dataType:'json',
            beforeSend :function(){},
            complete :function(){},
            success: function(res){
                console.log(res);
            }
        });

Upvotes: 1

Related Questions