0
retunコールで必要とされていないかを示す方法:は私が私のindex.phpを持っている全ページ
<?php
$sContent.='<script src="https://code.jquery.com/jquery-1.12.4.js"></script>';
$sContent.='<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>';
$sContent.='<script src="in.js" type="text/javascript"></script>';
$id=2;
$sContent.='<div id="agree">Agree to terms: <input type="checkbox" id="agreed" value=1></div>';
$sContent.='<br><br><div class="show"></div>';
if($_GET['f'] == 'showInfo')
{
$sContent.= 'This is the info about item id: '.$_GET['id'];
}
$sAction = $_SERVER['PHP_SELF']."?id=".$id."&f=showInfo";
$sDest.= '<br><input class="'.$id.'" type="button" id="'.$id.'" name="'.$id.'" value="Click to show info about item '.$id.'" onClick="javascript:showInfo(\''.$sAction.'\');">';
$sContent.= $sDest;
echo $sContent;
?>
そして、私のjsファイル内を:
function showInfo (action)
{
var aryAction = action.split('?');
params = aryAction[1];
var theUrl = 'index.php';
alert(aryAction[1]);
$.ajax ({
url: theUrl,
data: params,
async:true,
success: function (data, textStatus)
{
$('.show').html (data);
}
});
}
これは、全体の指数を示しdiv内の.phpをクラス 'show'に置き換えます。私はそれを望んでいない、私はちょうど 'これはアイテムのIDについての情報です:2'そのdivの、他に何もありません。
私は他の同様の記事を読んできましたが、多分私はajax関数を使用すべきではありません。
ありがとうございます!
あなたはちょうどあなたが欲しいものだけ返すようにPHPを変更することができませんか?あるいは、jQueryを使用して、ページ全体を受け取った後にのみそのセクションを抽出する必要があります – charlietfl