这是我的按钮
<button id="resend-invitation-button-<?php echo $user['id'] ?>"
class="btn btn-warning cp_width_100pct resend-invitation-button height_36px"rel="<?php echo $user['email'] ?>"><?php echo $this->translate->_("invite_again") ?></button
这是一条信息消息
<div id="user-invited-message-<?php echo $user['id']?>" class="alert alert-success org-user-messages" role="alert" style="display: none"><?php echo $this->translate->_("message_user_invited") ?></div>
这是我的ajax调用 当我单击“再次邀请”按钮时,应该显示一条信息,例如“已成功邀请” **
$('.resend-invitation-button').click(function() {
var email = $(this).attr('rel');
var data = {
email: email
};
console.log(data);
$.ajax("/organization/users/resendinvite",{
type: "POST",
data: data
})
.done(function(response) {
console.log(response);
if(response == 200) {
$('.org-user-messages').hide();
$('#user-invited-message-' + email).show();
$('#orgstatus-span-' + userId).text("INVITED SUCCESSFULLY");
}
if(response == 404){
$('.org-user-messages').hide();
}
if(response == 500){
$('.org-user-messages').hide();
$('#user-error-message-' + email).show();
}
})
.fail(function(response) {
console.log('FAILURE');
});
});
答案 0 :(得分:0)
<div class="the-return">
[HTML is replaced when successful.]
</div>
<script type="text/javascript">
$("document").ready(function(){
$(".js-ajax-php-json").click(function(){
var data = {
"action": "test"
};
data = $(this).serialize() `enter code here`+ "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: "response.php", //Relative or absolute path to response.php file
data: data,
success: function(data) {
$(".the-return").html(
"Favorite beverage: " + data["favorite_beverage"] + "<br />Favorite restaurant: " + data["favorite_restaurant"] + "<br />Gender: " + data["gender"] + "<br />JSON: " + data["json"]
);
alert("Form submitted successfully.\nReturned json: " + data["json"]);
}
});
return false;
});
});
</script>