zoukankan      html  css  js  c++  java
  • AS3.0和php数据交互POST方式


    AS3.0和php数据交互POST方式
    AS3.0和php数据交互POST方式
    首先打开flash建立一个as3.0的文件
    拖 textarea和button组建到舞台上
    分别给两个组件命名:txtcontent和addcontent

    然后点第一帧添加动作:
    var url:String = “http://localhost/tt.php”; //执行操作数据库的php文件
    var requestData:URLRequest = new URLRequest(url); //新建URLRequest对象,用来获取flash中textArea的数据
    var loader:URLLoader = new URLLoader(); //建立URLLoader对象,用来发送flash中textArea的数据
    addcontent.addEventListener(MouseEvent.CLICK,addData); //为button附事件对象,点击按钮执行addData函数
    function addData(e:Event){
    requestData.data = String; // .data 为URLRequest一个属性分三种大家可以查手册查到
    requestData.method = URLRequestMethod.POST; //.method 也为 URLLoader的一个属性值
    var urlvariables:URLVariables = new URLVariables(); //建立URLVariables对象,
    urlvariables.cc = txtcontent.text; //通过cc参数传递 txtcontent里的数据
    requestData.data = urlvariables;//讲urlvariables的数据赋值给.data
    loader.load(requestData); //开始发送数据
    }
    php文件很简单
    <?
    $content = $_POST["cc"]; //获取flash传递过来的参数
    $conn = mysql_connect(“localhost”,”root”,”123456″) or die(“mysql:”.mysql_error());
    mysql_select_db(“guestbook”,$conn) or die(“mysql:”.mysql_error());
    $sql = “insert into topic(content) values(‘$content’)”;
    mysql_query($sql);
    //以上为连接数据库并执行sql语句
    ?>


    我的代码:

            
    function sendPostJSON(array:Array):void {

    var variables:URLVariables = new URLVariables(); //建立URLVariables对象
    variables.name = 'HCity首都';
    variables.age = '25';

    /*
    * 如果使用json数据的方式
    var objectArray:String = '{"name":"didi","age":"28"}';
    var json = JSON.decode(objectArray);
    variables.name = json.name;
    variables.age = json.age;
    */

    var requert:URLRequest = new URLRequest('http://thinkphp3.com/addinfo.php');

    requert.method = URLRequestMethod.POST;

    requert.data = variables;

    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, onURLLoaderCompleteEvent);
    loader.load(requert);
    }

    private function onURLLoaderCompleteEvent(event:Event):void {
    var data:String = URLLoader(event.target).data;
    trace('onURLLoaderCompleteEvent ok:'+data);
    }


    php服务端的代码非常简单,就是把接收到的post数据提交数据库!
     

  • 相关阅读:
    杂项
    导出查询数据(大数据量)
    设置现有字段自增
    C++ 矩形交集和并集的面积-离散化
    Python使用flask架构、跨域
    匈牙利命名法
    C++ main函数
    windows编译boost
    mfc HackerTools监控键盘按键
    mfc HackerTools远程线程注入
  • 原文地址:https://www.cnblogs.com/didi/p/2343004.html
Copyright © 2011-2022 走看看