0

WordPress

I have a ajax function passing value to a function in functions.php The function on functions.php sends the response to ajax success but the value I am passing using ajax is not going to the function in functions.php

$.ajax({
        url: ajaxStuff.ajaxurl,
        type: "GET",
        processData :true,
        data: {
            action: 'filter_package',
            value: data,
        },
        
        success: function (data) {
            alert(data);
        },
    }); 

The console.log for data shows as:

{cat_names: Array(1), reg_names: Array(0), dest_names: Array(0), fromPrice: '', toPrice: '', …}

which is correct one.

If I enter some hardcoded message to my filter_package function in functions.php the ajax shows the response which means the ajax function hits my function on functions.php but when I try to get the data from ajax on my function I shows Array0

function filter_package()
{

    $value = $_REQUEST['value'];    
    $cat_slug = $value['cat_names'];
    echo 'sadasd'.$cat_slug;

The output:

sadasdArray0

1 Answer 1

0

check your ajax url and make sure admin.ajax hit correctly in networkbdev tools

also can check Ajax call to PHP action/function with array as data (in wordpress)

Sign up to request clarification or add additional context in comments.

4 Comments

I also have a contact form which sends mail to client using as like same ajax function and it works perfectly.
It seems my admin-ajax is returning 0 for this problem and is ok with contact form
sadasdArray0 in your output you have Array that comes from $cat_slug so everything is fine here. You just trying to echo an array, you better use print_r or var_dump function.
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.