如何显示什么是需要回访电话,而不是整个页面
How to show what is needed in retun call and not the whole page
我有在我的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中带有'show'类的整个index.php。我不需要这个,我只需要在div中写上" This is the info about item id: 2 "就行了。
我一直在阅读其他类似的帖子,也许我不应该使用ajax函数。有什么办法吗?非常感谢!
必须将HTML内容与字符串分开。
将这两个东西放在if
/else
子句中,然后它将工作:
<?php
$sContent = '';
if($_GET['f'] == 'showInfo')
{
$sContent .= 'This is the info about item id: '.$_GET['id'];
}
else
{
$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>';
$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;
相关文章:
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何在生成下载文件时显示加载动画
- React重新渲染但未显示正确的组件
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- HTML文本框,它接受电话号码,并以美国电话号码格式显示
- 如果电话号码已注册,则显示错误消息
- angularjs绑定赢得'除非我打GET电话,否则不会显示
- 指向电话号码的超链接,其中企业/人员的姓名显示在电话上
- 根据时区显示电话号码
- 谷歌地图API-格式化的电话号码显示为未定义的列表在侧栏上
- 如何显示什么是需要回访电话,而不是整个页面
- 在电话号码中突出显示号码
- 离子显示和情态-缓慢和错误,即使在快速的电话
- 如何修复显示自动2位数字的最后一个电话号码到第二个文本字段
- 如何显示自动2位数字的最后一个电话号码到第二个文本框
- 仅为国际访客显示国际电话格式
- 如何在"dumb"上获得动态(部分在被选择时显示)表单WAP电话(没有Javascript)