webtet 发表于 2017-3-26 07:49:23

php jquery ajax提交

function search_buyer(email){
            var content = 'email='+$(email).val();
            var url = '/index.php?r=admin/ajaxBuyer';
            $.ajax(
                {   type: "post",
                  url:url,
                  data: content,
                  dataType:'json',
                  success: function(msg){
                        $('#ip').val(msg['info']['ip']);
                        $('#log').innerHTML = msg['sendlog']['list'];

                  }
                }
            )
      }


    public function actionAjaxBuyer(){

      $result=array();
      try{
            if(isset($_POST['email']) && empty($_POST['email'])){
                throw new Exception('Email 不能为空!');
            }
            $email= trim($_POST['email']);
            if ( !preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email)) {
                throw new Exception('Email 格式有误!');
            }

            $result['data']=$model->getLastBuyerInfo($email);

      }catch (Exception $e){
            $result['errmsg']=$e->getMessage();
      }
      echo json_encode($result);
    }
页: [1]
查看完整版本: php jquery ajax提交