尝试将Jquery .load()与多个ID选择器一起使用没有成功

时间:2018-08-13 00:41:40

标签: javascript php jquery

从本质上讲,用户单击电影标题,并且情节和演员表都填充在我的可折叠对象中。如果我仅将1个选择器用于情节或演员表,但不能同时使用两者,则效果很好。有什么想法或例子吗?谢谢

HTML ...

<div data-role="main"  class="ui-content">
    <div data-role="collapsibleset">
        <div data-role="collapsible">
            <h1>Plot</h1>
            <p id="dvdinfo"></p>
        </div>

        <div data-role="collapsible">
            <h1>Cast</h1>
            <p id="dvdcast"></p>
         </div>
    </div>
</div>

JavaScript ...

function getmoviepic_mobile(movietitle) {
    var Movie = $(movietitle).text();

    $('#dvdinfo','#dvdcast').load('getuser2_mobile.php', {input:Movie}); 
}

PHP ...

<?php

include("includes/connection.php");

$q1 = trim($_POST['input']);
$result = mysql_query("
    SELECT 
         id, title, actors, plot, catagory, release_date, rated
    FROM ".TBL_DATA." 
    WHERE title = '".$q1."'");

while($row = mysql_fetch_array($result)) {
    echo $row['plot'];
    echo $row['actors'];
}

2 个答案:

答案 0 :(得分:0)

替换此行

$('#dvdinfo','#dvdcast').load('getuser2_mobile.php', {input:Movie}); 

与此一起

$('#dvdinfo,#dvdcast').load('getuser2_mobile.php', {input:Movie}); 

答案 1 :(得分:0)

PHP:

while($row = mysql_fetch_array($result)) {
    $x=[
        'plot'=>$row['plot'],
        'actors'=>$row['actors']
    ];
}
echo json_encode($x);

JS:

function getmoviepic_mobile(movietitle) {
    var Movie = $(movietitle).text();
    $.getJSON('getuser2_mobile.php', {input: Movie}, function(json, textStatus) {
        $('#dvdinfo').html(json.plot);
        $('#dvdcast').html(json.actors);
    });
}