Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a array variable in jQuery which is created as follows:

var values = $('input:checked').map(function() {
    return this.value;
    }).get();

Assume the values in the array variable as 1,2,3. I am trying to pass this variable to php using the below ajax call:

doAjaxCallDelete("delete_checked", "values");

The ajax function is written as below:

function doAjaxCallDelete(mode, values) {
    $.ajax({
        url: ajaxURL,
        type: "post",
        data: {mode: mode, values: values},
        async: false,
        success: function(data){
            responseData = data;
        },
        error:function(){
            alert('Connection error. Please contact administrator. Thanks.');
        }
    }); 
    return responseData;
}

I am retrieving this value in php using:

$myArray = $_REQUEST["values"];

But when I echo $myArray its showing 'values' instead of the real values inside the variable. Can anybody suggest a solution to pass values of the array variable properly. Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

it is the double quotes you use in the function call

doAjaxCallDelete("delete_checked", "values");

you pass a string "values" instead of variable values.

use doAjaxCallDelete("delete_checked", values); instead.

note:

use $_POST['values'];

share|improve this answer
 
What a silly mistake from my part. Thank you so much for pointing that out......was giving me a headache. Thanks a bunch. –  Elvin Varghese Oct 21 at 11:10
 
it happens, all the best ;) –  Shathish Oct 21 at 11:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.