[英]JQuery replacewith not working after Ajax call
Im doing a AJAX call and once I get the response, I want to replace a submit button with a label...But this is not working. 我正在做一个AJAX呼叫,一旦得到响应,我想用标签替换一个提交按钮...但是这不起作用。 I get the alert msg ie;
我得到警报信息,即; the response from the Ajax call but the replacewith command fails.
来自Ajax调用的响应,但replacewith命令失败。
Can you please tell me what is the mistake Im doing.. 你能告诉我我在做什么错..
Replacewith command Replacewith命令
$( this ).closest( 'tr' ).find( 'input:label' ).replaceWith("<label for=\'success\'>SUCCESS</label>");
Code: 码:
$("#table_appl,#table_enfr,#table_det01,#table_det02,#table_det03,#table_det04,#table_det05,#table_datais").on( "click", "input:submit", function( event ) {
//alert('Hi')
//event.preventDefault();
var fieldvalue = $(this).closest('tr').find('input:text').val();
var fieldname = $(this).closest('tr').find('input:text').attr('name');
alert('fieldname = ' + fieldname)
alert('fieldvalue = ' + fieldvalue)
$.ajax({
type:"GET",
url:"/validate/",
data:{'fieldvalue':fieldvalue,'fieldname':fieldname},
success:function(data){
if (data == 'Y'){
var item = $(this).closest('tr').find('input:label')
alert("Gonna be replaced" + item);
$( this ).closest( 'tr' ).find( 'input:label' );
$( this ).closest( 'tr' ).find( 'input:label' ).replaceWith("<label for=\'success\'>SUCCESS</label>");
}
alert("Response = "+ data);
}
});
return false;
})
And here's the code: 这是代码:
<form role="form" method="POST" action="/validate/" id="input_form">
<input id="myInput">
<button type="submit" id="submitButton">Click me!</button>
</form>
with the script: 使用脚本:
$("#submitButton").click(function () {
event.preventDefault();
$.get("/validate/", function (d){
if (d == "Y"){
$("#submitButton").replaceWith("<label>SUCCESS</label>");
}
})
})
Is this about what you want? 这就是你想要的吗? I guess you'll have to adapt the
.replaceWith()
part to find the correct element... 我猜你将不得不改编
.replaceWith()
部分以找到正确的元素...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.