夺命雷公狗jquery---57Ajax+XML实现对大批量数据的编辑
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="js/jquery.js"></script> <script> $(function(){ $('#btnok').bind('click',function(){ var first = $('#first').val(); var second = $('#second').val(); var data = { 'first':first, 'second':second }; //发送ajax请求 $.post('ajax6.php',data,function(msg){ //第一种方案 /* var jia = msg.getElementsByTagName('jia')[0].childNodes[0].nodeValue; var jian = msg.getElementsByTagName('jian')[0].childNodes[0].nodeValue; var cheng = msg.getElementsByTagName('cheng')[0].childNodes[0].nodeValue; var chu = msg.getElementsByTagName('chu')[0].childNodes[0].nodeValue; alert(jia+'--'+jian+'--'+cheng+'--'+chu); */ //第二种方案 var jia = $(msg).find('jia').text(); var jian = $(msg).find('jian').text(); var cheng = $(msg).find('cheng').text(); var chu = $(msg).find('chu').text(); alert(jia+'--'+jian+'--'+cheng+'--'+chu); },'xml') }); }); </script> </head> <body> 第一个数:<input type="text" id="first" /> <hr /> 第二个数:<input type="text" id="second" /> <hr /> <input type="button" id="btnok" value="计算" /> </body> </html>
PHP代码如下:
<?php $first = $_POST['first']; $second = $_POST['second']; $jia = $first + $second; $jian = $first - $second; $cheng = $first * $second; $chu = $first / $second; $str = <<<str <counter> <jia>$jia</jia> <jian>$jian</jian> <cheng>$cheng</cheng> <chu>$chu</chu> </counter> str; header("Content-Type:text/html;charset=utf-8"); echo $str;