早上/下午,伙计们。
编写一些 JQuery AJAX shizz 并遇到了一些困难。我已经完美地完成了调用 php 文件的实际过程,它只是试图让页面上的 html 以我想要的方式进行更改。我想去掉 a 和 ajax 调用等中使用的 id,并将其替换为从 PHP 文件传递的 html。代码如下...
$(".save_places").click(function() {
$.ajax({
url: "{/literal}{$sRootPath}{literal}system/ajax/fan_bus.php",
type: "POST",
data: ({id : this.getAttribute('id')}),
dataType: "html",
success: function(msg){
$(this).before(msg);
$(this).empty();
alert(msg);
}
});
return false;
});
HTML 非常简单;
<p class="links">
<a href="#" class="save_places" id="bus_{$businesses.results[bus].id}_{$sMemberDetails.id}"><img src="{$sThemePath}images/save_places.png" alt="Save to My Places" /></a>
<a href="#"><img src="{$sThemePath}images/send_friend.png" alt="Send to a Friend" /></a>
</p>
成功函数中的所有内容都是实验性的代码混搭,请问有什么帮助吗?
一如既往地感谢。
最佳答案
我认为你想要的是 .replaceWith()
,像这样:
$(this).replaceWith(msg);
这取代了 <a></a>
内容返回 msg
.
此外,如果您确定元素有 ID,您可以这样做:
data: {id : this.id},
关于html - PHP/JQuery/AJAX,一些初期问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2896671/