Get div content with jQuery for PHP -
update: wow fastest response ever , many answers in minutes of each other. amazing. ok here trying do. http://edvizenor.com/invoice33/
i want edit invoice on fly when hit blue box @ top want preview or see content on next page contained php var echoed out.
this blue box change later button @ bottom testing using it.
as see calls ajax script need edited content of div sent php var can echo on preview page. if can put in php var on next page. make sense? guys quick responses.
old post
is possible contents of div
using jquery , place them in php var send via or post?
i can contents of div
jquery this:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> $(document).ready(function() { $("#mybutton").click(function() { var htmlstr = $("#mydiv").html(); }); }); </script>
but how put jquery var in php var. need button press too. not included in code above. need because div
file changeable , when hit update , send via php needs have latest content.
according situation, trying send javascript variable php. common way exchange in json format,
for example, suppose have basic text editor
jquery:
$($document).ready(function(){ $("#submit-button").click(function(){ $.post('yourphpscript.php', { //this php var: //this javascript variable: 'text' : $("#some_text_area").text() }, function(response){ //to avoid js fatal error: try { var result = json.parse(response); //get php if ( result.success){ alert('successfully changed') } } catch(e){ //response isn't json } }); }); });
php code
<?php /** * * processing variable javascript */ if ( isset($_post['text']) ){ //do smth, save database } /** * if want show "success message" * div or textarea changed * can send result javascript via json */ $some_array = array(); $some_aray['success'] = true; die( json_encode($some_array) );
Comments
Post a Comment