0
我想創建一個登錄表單,我發佈用戶名和密碼到服務器,並獲得響應處理徹底的Ext.Ajax調用。下面是我的代碼:試圖獲得響應從服務器與sencha的Ext.Ajax調用2
我的登錄表單
Ext.define('GS.view.Main', {
extend: 'Ext.form.Panel',
config: {
fullscreen: true,
id: 'register',
frame:true,
items: [{
xtype: 'fieldset',
items: [
{
xtype: 'textfield',
name : 'userName',
itemId: 'userName',
placeHolder : 'Orgnisationsnummer',
},
{
xtype: 'passwordfield',
name : 'password',
itemId: 'password',
placeHolder : 'Lösenord'
}
]
}, {
xtype: 'button',
text: 'Logga in',
minHeight: '45px',
action: 'submitFormAction'
}]
}
});
我控制器
Ext.define('GS.controller.Controller', {
extend : 'Ext.app.Controller',
config : {
control : {
'button[action="submitFormAction"]' : {
tap : 'submitForm'
},
}
},
submitForm : function() {
var form = Ext.getCmp('register');
Ext.Ajax.request({
url : "URL HERE",
params : { username : form.getValues().userName, password: form.getValues().password },
method: 'POST',
success: function (result, request) {
console.log(result);
var jsonData = Ext.decode(result.responseText);
Ext.Msg.alert('Success', 'Data return from the server: '+ jsonData.msg);
},
failure: function (result, request) {
Ext.Msg.alert('Failed', result.responseText);
}
});
}
});
我簡單的PHP腳本
<?php
$username = $_POST["userName"];
$password = $_POST["password"];
if(!empty($username) && !empty($password)) {
$response = array("success" => 'true', 'id' => '1');
echo json_encode($response);
}
?>
問題是我從中得到響應發球r:
getAllResponseHeaders: function() {
getResponseHeader: function (header) {
request: Object
requestId: 1
responseText: ""
responseXML: null
status: 200
statusText: "OK"
__proto__: Object
Error: You're trying to decode an invalid JSON String:
這是怎麼回事?我究竟做錯了什麼?我是否沒有正確發佈表單值?
謝謝!
/福利局的:)
啊,昨晚錯過了!謝謝! – Ismailp