如何运行php函数并使用javascript / jquery在页面上显示内容?

I have a php script which gets all my movies from a specific category and echos the html output using foreach loop placed inside of a function.

Instead of displaying the entire library at once I'd like to display it one category at a time by clicking a button (without page refresh) for example:

User clicks "Action" button:

<li><a href="javascript:Action();">Action</a></li>

Which activates Action();

function Action()
{
    jQuery.ajax({
    type: "POST",
    url: 'index2.php',
    dataType: 'json',
    data: {functionname: 'Movies', arguments: ['Action']},

    success: function (returnData) {
                    data = returnData;
                  document.getElementById("Action").innerHTML = returnData;
                  console.log(data);
            }
});
}

Action Div:

<a id="Action"></a></div>
<h3><span>Action</span></h3></center>
<div id="detail[19]">
</div>

The PHP function is Movies($var) when passing "Action" into it, it runs fine. So what do I do in order to get "Movies(Action)" to print to "detail[19]"

The PHP function:

function Movies($category){ 
$movies = glob('./uploads/Videos/Movies/'.$category.'/*/*.{mp4,m4v}', GLOB_BRACE);
global $images,$temp,$emtyImg,$actual_link,$dir,$rmvd;
       foreach ($images as $image) {
        $lookup[pathinfo($image, PATHINFO_FILENAME)] = $image;
    }

    foreach ($subs as $sub) {
        $lookup2[pathinfo($sub, PATHINFO_FILENAME)] = $sub;
    }
    echo '<div id="detail['.$rmvd.']">';
    include($_SERVER['DOCUMENT_ROOT']."/scripts/amzn.php");
    foreach ($movies as $movie) {

    *Lot's of useless code that echos div's with videos in them*    }
    echo '</div>';
    $rmvd++;
}

I know I'm missing what I need for the PHP side and likely messed up the jquery bit. I'm at a loss at how to continue successfully.

You need to return a json object in php so that javascript can read it. For example:

<?PHP
$data = /** whatever you're serializing **/;
header('Content-Type: application/json');
echo json_encode($data);