简体   繁体   中英

parsing text with html tags using jquery

to parse an html element to be used in after click the submit , im using this method

 $panel = $('.box').html();
 $("#page").append('<form  name="sampleForm" method="post" action="ticket.form.php"><input type="hidden" name="ConfirmationPanel" value=""></form>');

    document.sampleForm.ConfirmationPanel.value = $panel;
    document.forms["sampleForm"].submit();

and then after the submit click , i'm requesting the POST variable , and insert the content text of the POST variable to the page :

 var $_POST = <?php echo json_encode($_POST); ?>;
if($_POST["ConfirmationPanel"].length > 0)
{
$('#tabspanel').before($_POST['ConfirmationPanel']);
}

i can successfully access to the variable and also use it , and the every thing is fine , one probléme is , jquery insert the content of the POST variable like text , like this (" <div><h1>Test</h1></div> ") , what i want is to insert it like this ( <div><h1>Test</h1></div> ) without the ( " " ) , so to be one of the page html elemnts

otherwise : i insert the text from the POST variable befor $('#tabspanel') , jquery insert it as a text like this : <div id="tabspanel" >"<div><h1>Test</h1></div>"</div> , i want jquery to insert it as html element until i can see the (div) and the (h1) , so to be like this : <div id="tabspanel" ><div><h1>Test</h1></div></div>

You need to access the post variable from a different PHP page. Eg ajax the form results to another PHP page, then return the success/failure of it as plain text and test against it in the current page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM