欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          thinkPHP5 ajax提交表單操作實(shí)例分析

          thinkPHP5 ajax提交表單操作實(shí)例分析

          本文實(shí)例講述了thinkPHP5 ajax提交表單操作。分享給大家供大家參考,具體如下:

          <!DOCTYPE html> <html>   <head>     <meta charset="UTF-8">     <title></title>     <script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>     <script>       function ajaxPost(){         var formData = $("#myform").serialize();         //serialize() 方法通過序列化表單值,創(chuàng)建 URL 編碼文本字符串,這個(gè)是jquery提供的方法         $.ajax({           type:"post",           url:"{:url('Index/index/test')}",           data:formData,//這里data傳遞過去的是序列化以后的字符串           success:function(data){             $("#content").append(data);//獲取成功以后輸出返回值           }         });       }     </script>   </head>   <body>     <form id="myform"><!--這里給表單起個(gè)id用于獲取表單并序列化-->       <input type="text" name="mess" />       <input type="text" name="id" />       <button onclick="ajaxPost()">---------</button>     </form>     <p id="content">     </p>   </body> </html>

          其實(shí)跟正常的ajax沒什么區(qū)別,主要就是利用jquery的serialize()方法序列化表單

          中間遇到些麻煩就是還沒熟悉thinkphp5框架,之前一直用的3.2.3還沒來得及,倆版本差別還是有的

          一個(gè)是$_POST不能用了還有就是原來ajax的url可以使用框架的U方法沒了具體看了看think下的助手函數(shù)發(fā)現(xiàn)是url

          下邊是隨便寫了個(gè)方法用于返回json數(shù)據(jù)

          public function test($mess,$id){     if($mess == '123'){       return json("ajax成功!".$mess."---".$id);     }else{       return json("你輸出的是其他值:".$mess."---".$id);     } }

          此外,常規(guī)的參數(shù)提交與處理方法如下:

          表單提交傳參:

          <input type="hidden" name="project_name" value="$project_name"/>

          在控制器中獲取

          $project_name=input("post.project_name");

          php中跳轉(zhuǎn)傳參:

          $this->success('新增項(xiàng)目成功',url("Version/index",array('project_name'=>$project_name))); die;

          相關(guān)學(xué)習(xí)推薦:thinkphp

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)