0

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.

1 Answer 1

1

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'];

2
  • What a silly mistake from my part. Thank you so much for pointing that out......was giving me a headache. Thanks a bunch. Commented Oct 21, 2013 at 11:10
  • it happens, all the best ;) Commented Oct 21, 2013 at 11:20

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.