0

I want to send an array generated in jQuery to a php file. I get stuck on this. I tried several way but no luck. I want to echo/print_r the array in php file. Experts give me your kind look. My code is given below :

js:

<script>
    jQuery(document).ready(function($){
        url = '<?php echo includes_url().'cs_cause.php'; ?>';
        var allVals = [];
        $('#deleteProduct').click(function(){

            $('.delete-product:checked').each(function() {
                allVals.push($(this).val());
            });
            $.post(url,{ array : allVals }, function(response,status){
                    alert( response+ '  ' + status);
            });
        })
    })
</script>

php :

<?php
    if($_POST['array'])
    {
        $r = $_POST["array"];
        print_r($r);
    }
?>
5
  • so how can I get the array ?? Commented Mar 3, 2015 at 6:27
  • whats the response by the way? use console.log(response) Commented Mar 3, 2015 at 6:29
  • pls have a look : screencast.com/t/shpt3IpLOI2 @Ghost Commented Mar 3, 2015 at 6:34
  • Your url path seems to be wrong mate..Where is your cs_cause.php file located Commented Mar 3, 2015 at 6:43
  • it is in : wp-content\themes\aidreform\include\cs_cause.php i would like to mention that , my script and php stuff both are in the same file. Commented Mar 3, 2015 at 6:45

1 Answer 1

1

Try something like this mate.

<script>
    jQuery(document).ready(function($){

        url = "http://localhost/fundraise/wp-content/themes/aidreform/include/cs_cause.php"; 
        var allVals = [];
        $('#deleteProduct').click(function(){

            $('.delete-product:checked').each(function() {
                allVals.push($(this).val());
            });
            $.post(url,{ array : allVals }, function(response,status){
                    alert( response+ '  ' + status);
            });
        })
    })
</script>

Incase u move this file to the server change the url to

url = "/wp-content/themes/aidreform/include/cs_cause.php"; 
Sign up to request clarification or add additional context in comments.

3 Comments

how u know it is - "localhost/fundraise" ?? now it shows : screencast.com/t/RiDSzAXF
Thank u very much .. I fixed it out .. I just moved my php stuffs into a new file. now its working !! :) .. Thanks a lot. I have question of curiosity that how do u know the name "localhost/fundraise" ??? and what was the problem when i used "include_url()" ?

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.