[英]Uncaught TypeError: Cannot read property 'getProxy' of undefined
[英]Uncaught TypeError: Cannot read property 'responseText' of undefined
buttons: [
{
text: "Add User",
id: "new-record-add-button",
handler: function() {
var form = this.up('form').getForm();
form.submit({
url: BasePath+'/main/admin/adduser',
method: 'POST',
waitTitle: 'Authenticating',
waitMsg: 'Please Wait',
success: function(form, action) {
win.close()
Ext.Msg.show({
title:'Success'
,msg:'User added successfully'
,modal:true
,icon:Ext.Msg.INFO
,buttons:Ext.Msg.OK
});
},
failure: function(form, action) {
console.log(action.response.responseText);
obj = Ext.JSON.decode(action.response.responseText);
console.log(obj);
Ext.Msg.alert('Error',obj.errors)
form.reset();
}
})
//this.up("window").close();
}
},
{
text: "Cancel",
handler: function() {
this.up("window").close();
}
}
]
當我以表單到達故障功能時,出現以下錯誤:
Uncaught TypeError: Cannot read property 'responseText' of undefined
這是我的PHP代碼:
public function adduserAction()
{
$response = new JsonModel();
//$error = array();
$errors="";
if(!ctype_alpha($_POST["first_name"])) {
$errors.="First Name cannot contain characters and numbers";
}
if(!ctype_alpha($_POST["last_name"])) {
$errors.="Last Name cannot contain characters and numbers";
}
if(!filter_var($_POST['email_address'], FILTER_VALIDATE_EMAIL)) {
$errors.="Email should be of the format john.doe@example.com";
}
if(empty($_POST["role"])) {
$errors.="Role cannot be empty";
}
if($errors!="") {
$response->setVariables(array("success"=>false, "errors"=>$errors));
}
else {
$response->setVariables(array("success"=>true, "errors"=>$errors));
}
return $response;
}
responseText
是ExtJs的東西-它表示在解碼之前從服務器返回的實際文本(例如,使用echo
)。
您應該在operation
或request
對象中的異步回調中獲取它,除非發生某種服務器異常或將success
設置為false
,這就是為什么不在失敗處理程序中獲取它的原因。
為了真正了解它的功能,我建議您看一下Connection.js 。
如果您通過ExtJs提交表單,則在表單提交成功后,需要將response.responseText設置為{“ sucess”:“ true”}。 如果要將表單提交到某個頁面,則必須確保要從后端返回此對象。 否則,您必須重寫現有的onSuccess方法。
第二種方法是這樣的
Ext.override(Ext.form.action.Submit,{ onSuccess: function(response) { var form = this.form, success = true, result = response; response.responseText = '{"success": true}'; form.afterAction(this, success); } });
將此片段放在您的應用程序中,然后看一下魔術。 干杯。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.