[英]I want to set a url inside my ajax call back function
I want to make a clickable link in my ajax success response.我想在我的 ajax 成功响应中创建一个可点击的链接。 But I could not do this.但我不能这样做。
<td id="attachment"></td>
function DoAction(id) {
$.ajax({
type: "get",
url: "/view_message",
data: "id=" + id,
dataType: 'json',
success: function(data) {
if (data) {
var text = "No Files There !";
$('#myModal').modal('show');
$('#subject').text(data.subject);
$('#body').text(data.body);
$('#created_at').text(data.created_at);
if (data.attachment) {
$('#attachment').html('<a href="files/' + data.attachment + '" />click</a>');
} else {
$('#attachment').text(text);
}
}
}
});
}
I want to display a clickable link in my .我想在我的 .
I always encounter this when using ajax calls so;我在使用 ajax 调用时总是遇到这种情况;
Update your code from this.从此更新您的代码。
$('#attachment').html('<a href="files/' + data.attachment + '" />click</a>');
To This.到此。
$(document).find('#attachment').html('<a href="files/' + data.attachment + '" />click</a>');
if the code doesn't work add a console.log("working")
function to see if your code is really reaching the success function.如果代码不起作用,请添加一个console.log("working")
函数以查看您的代码是否真的达到了成功函数。
I hope it helps.我希望它有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.