Curl_xml.html:
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Curl submits XML data</title>6 <Scriptsrc= "Http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></Script>7 <Script>8 $(function(){9 $('input[type= "button"]'). Click (function(){Ten //Alert (decodeuricomponent (' form '). Serialize ()); The decodeURIComponent () function decodes the URI encoded by the encodeURIComponent () function One $.ajax ({ A URL:'curl_xml.php', - Type:'Post', - Data: $ ('form'). Serialize (), the Success:function(data, status, XHR) { - $('#box'). HTML (data); - } - }); + }); - }) + </Script> A </Head> at <Body> - <form> -Product Name:<inputtype= "text"name= "Goods_name"><BR/> -Commodity Price:<inputtype= "text"name= "Goods_price"><BR/> -Product Categories:<Selectname= "Goods_brand"> - <optionvalue= "Computer">Computer</option> in <optionvalue= "tablet">Plate</option> - <optionvalue= "mobile">Cell phone</option> to <optionvalue= "Cellular">Cell phone</option> + </Select> - <BR/> theWhether to ship:<inputtype= "Radio"name= "Issend"value= "Yes">Is<inputtype= "Radio"name= "Issend"value= "No">Whether<BR/> * <inputtype= "button"value= "Submit"> $ </form>Panax Notoginseng <DivID= "box"></Div> - </Body> the </HTML>
Interface:
curl_xml.php:
1<?PHP2 $goods _name=$_post[' Goods_name '];3 $goods _price=$_post[' Goods_price '];4 $goods _brand=$_post[' Goods_brand '];5 $issend=$_post[' Issend '];6 7 $xml= <<<XML8<?xml version= "1.0" encoding= "Utf-8"?>9<goods>Ten<goodsname>$goods _name</goodsname> One<goodsprice>$goods _price</goodsprice> A<goodsbrand>$goods _brand</goodsbrand> -<issend>$issend</issend> -</goods> the XML; - - $url= "http://localhost/test/curl_xml_deal.php"; - + $ch=curl_init (); - +curl_setopt ($ch, Curlopt_url,$url); Acurl_setopt ($ch, Curlopt_returntransfer,true); atcurl_setopt ($ch, Curlopt_post,true); -curl_setopt ($ch, Curlopt_postfields,$xml); - - $res= Curl_exec ($ch); - -Curl_close ($ch); in - Echo $res; to?>
curl_xml_deal.php:
1 <? 2 $xmlfile_get_contents("Php://input"); 3 $sxe simplexml_load_string ($xml); 4 Var_dump ($sxe); 5 // Echo $sxe [0]->goodsname; Product Name 6 ?>
Results:
Ajax+curl+simplexmlelement processing Data