0

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",
        data: "msg="+custM
    });     
});

<div id="customMsgPreview">
    <div class="rollSec">
    <pre>
      // SUBMITTED TEXT NEEDS TO APPEAR HERE 
      '.$tstLnk.'
    </pre>
</div>

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You can pass success callback:

success: function (text) {
  $('#customMsgPreview pre').html(text);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.