Update text with submitted data w/jQuery
I have a form on a page. I have a link acting as submit button. The value is sent to a php page via ajax where the value is set into a session.
After submit I swap the form with text field where the text is displayed. How do I use the text from the submitted form to display withing <pre></pre>
tags?
$("#btnPreview").click(function() {
var custM = $("#inviteMsg").val();
$.ajax({
url: "ajax.php",
type: "POST"开发者_StackOverflow中文版,
data: "msg="+custM
});
});
<div id="customMsgPreview">
<div class="rollSec">
<pre>
// SUBMITTED TEXT NEEDS TO APPEAR HERE
'.$tstLnk.'
</pre>
</div>
Use $.ajax
's success
callback.
var custM = $("#inviteMsg").val();
$.ajax({
url: "ajax.php",
type: "POST",
data: "msg="+custM,
success: function(response){
$('#customMsgPreview').find('pre').html(custM);
}
});
You can also put response
from the ajax page in the pre
tag as well.
You can pass success callback:
success: function (text) {
$('#customMsgPreview pre').html(text);
}
精彩评论