开发者

Update text with submitted data w/jQuery

开发者 https://www.devze.com 2023-04-07 03:58 出处:网络
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.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消