Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Zend Framework 2中处理ajax post数据_Php_Jquery_Ajax_Zend Framework_Zend Framework2 - Fatal编程技术网

Php 在Zend Framework 2中处理ajax post数据

Php 在Zend Framework 2中处理ajax post数据,php,jquery,ajax,zend-framework,zend-framework2,Php,Jquery,Ajax,Zend Framework,Zend Framework2,所以我有一些信息是通过Post ajax请求发送的,如下所示: $.ajax("<?php echo $this->url('panel/academy/locals/editlocal')?>", { method: 'POST', data: { id: id, // number distrito: newDistrito, //

所以我有一些信息是通过Post ajax请求发送的,如下所示:

$.ajax("<?php echo $this->url('panel/academy/locals/editlocal')?>", {
                method: 'POST',
                data: {
                    id: id, // number
                    distrito: newDistrito, // string
                    direccion: newDireccion, // string
                    telefono1: newTelf1, // string
                    telefono2: newTelf2, // string
                        efectivo: $('#local_'+id).find('.efectivo').prop('checked'),
                        visa: $('#local_'+id).find('.visa').prop('checked'),
                        mastercard: $('#local_'+id).find('.mastercard').prop('checked'),
                        american: $('#local_'+id).find('.american').prop('checked'),
                        deposito: $('#local_'+id).find('.deposito').prop('checked'),
                    central: newCentral,
                }
            })
问题是,当我尝试向localForm添加一个元素,该元素包含一个布尔值(如复选框)时,该表单总是无效的,因此我从未访问数据库并保存用户所做的更改。我尝试使用$prg数组来访问信息,但也没有成功。我怎样才能完成这个?我是否尝试了错误的方法

提前谢谢

这是完整的表格

<?php

namespace GrouPanel\Form\Locals;

use GrouCore\Form\Form;
use GrouCore\Form\Element\DistrictSelector;
use GrouCore\Form\Element\UserPhone;
use GrouCore\Form\Element\LocalAddress;
use Zend\Form\Element\Checkbox;

class LocalForm extends Form {
    public function __construct($name = "localForm") {
    parent::__construct ( $name );
    $this->setAttribute ( 'novalidate', 'novalidate' );

    $localDistrict = new DistrictSelector ( 'distrito' );
    $localAddress = new LocalAddress ( 'direccion' );
    $localPhone1 = new UserPhone ( 'telefono1' );
    $localPhone2 = new UserPhone ( 'telefono2' );
    $localCentral = new Checkbox ( 'central' );

    $this->add ( array (
            'name' => 'id',
            'type' => 'text'
    ) );
    $this->add( $localDistrict )
        ->add( $localAddress )
        ->add ( $localPhone1 )
        ->add ( $localPhone2 )
        ->add ( $localCentral );
    $this->getInputFilter ();
}

您使用语法jQuery.ajax(url[,settings])。尝试添加密钥:

dataType: 'json',

在你的设置结构中

Http在发送之前将所有内容字符串化。 因此,在js中可以使用1或0,而不是true或false

efectivo: ($('#local_'+id).find('.efectivo').prop('checked')) ? 1 : 0,
添加到ajax

dataType: 'json',

您能否与LocalForm共享您的验证类型,以及您的复选框是否有指定的值?@xangxiong添加了该表单。因此,由于您使用的是Zend\Form\Element\checkbox,我相信选中复选框时它会查找1,而未选中复选框时它会查找0。在复选框的HTML定义中,值是否设置为1?或者,不要通过POST发送布尔值,而是发送0/1。
dataType: 'json',