2012-07-04 54 views
2

在firebug中,在POST标签中,我看到以下内容;从PHP接收JSON请求

JSON   

textfieldone "Alex" 



Source 
{"textfieldone :"Alex"} 

但在PARAMS标签我看到

_dc 1341332451114 

在我的PHP代码时,我print_r($_REQUEST);我得到

Array 
(
    [_dc] => 1341332451114 
) 

,而不是JSON,这是在POST选项卡中找到。我怎么解决这个问题?

我不知道这是为什么hapenning,我试图调试此整天

UPDATE PHP代码:

<?php 
// Make a MySQL Connection 
mysql_connect("localhost", "root", "pwd") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 

print_r($_REQUEST); 

在Firebug我看到网址下方的上述Responces;

POST http://localhost/proj/php/result.php?_dc=1341332451114 200 OK 107ms 

我可以知道?_dc=1341366375982是什么。我送POST

更新2

EXT JS4代码

模型

Ext.define ('Mycomp.model.MyClass',{ 
    extend: 'Ext.data.Model', 

    fields:['textfieldone'] 

}); 

VIEW

Ext.define('Mycomp.view.user.MyClassView', { 
    extend: 'Ext.window.Window', 
    alias: 'widget.myclassview', 
    initComponent: function() { 
     this.items = [ 
      { 
       xtype: 'form', 
       items: [ 
        { 
         xtype: 'textfield', 
         name : 'textfieldone', 
         fieldLabel: 'Contact Person Name' 
        } 
       ] 
      } 
     ]; 
     this.buttons = [ 
         { 
          text: 'Save', 
          name:'save', 
          action: 'save' 
         } 
        ]; 
     this.callParent(arguments); 
    } 
}); 

控制器

Ext.define('Mycomp.controller.MyClass',{ 
    extend: 'Ext.app.Controller', 

    stores:['MyClass'], 
    models:['MyClass'], 
    views:['MyClassView'], 
    init: function(){ 
     this.control({   
      'myclassview button[action=save]': { 
       click: this.myMethod 
      } 
     });   
     }, 
     myMethod: function(button, record) { 

     var win = button.up('window'), 
      form = win.down('form'), 
      values = form.getValues(), 
      store = this.this.getmyClassStore(), 
      model = store.model, 
      record = model.create(); 


      record.set(values); 
      store.add(record); 
      win.close(); 
      store.sync(); 
} 
}); 

STORE

Ext.define('Mycomp.store.Myclass',{ 
    extend:'Ext.data.Store', 
    model:'App.model.Myclass', 

    proxy: { 
     actionMethods : { 
      create : 'POST' 
     }, 
     type: 'ajax', 
     url : '/savetodb.php' 

    } 

}); 
+1

显示您的代码plz。 – xdazz

+0

你确定它没有返回404吗? –

+0

我已经在上面添加了我的PHP代码。并且我没有收到404 – Illep

回答

2

我想你要设置你的PHP文件头就可以提供JSON:

header('Cache-Control: no-cache, must-revalidate'); 
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Content-type: application/json'); 
+0

我应该在哪里添加这些代码? – Illep

+0

这是从* PHP发送* JSON *。问题是关于*在POST请求中从客户端接收* JSON。 –

+0

Whelp - 我迷路了。 @Illep能否让我快速写下你有什么文件和他们想要的相互作用。 – badcircle

2

尝试下面的代码,它应该解决您的问题:

<?php 
    var_dump(json_decode(file_get_contents('php://input'))); 
?>