我的观点包含以下代码
this.keypadDisplay = Ext.create('Ext.field.Text', {
xtype:'textfield',
disabled: true,
value: ''
});
我的ajax请求代码是
handler: function(b, e) {
var thisUser = this.getValue();
alert(thisUser);
//params[this.getSubmitParamName()] = this.getValue();
Ext.Ajax.request({
url:'http://localhost/sencha2011/keypadapp/code.php',
params: thisUser,
method:'GET',
success: function(response, opts){
var text = response.responseText;
console.log(response.responseText);
alert(thisUser);
//alert(this.getValue());
//alert('Value: ' + this.getValue());
Ext.Msg.alert('success', text);
},
failure: function(response, opts){
Ext.Msg.alert('Error','Error while submitting the form');
console.log(response.responseText);
},
scope: this
});
}
这里我成功地获得了“this.getValue”。我想插入this.getValue到代码表。 我的code.php包含以下代码
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db('form',$con);
$insert = "INSERT INTO codetable(password) VALUES ('".$_GET['thisUser.value']."')";
if(mysql_query($insert))
{
echo('values inserted successfully');
}
else
{
echo('failure' . mysql_error());
}
?>
这里我在第5行得到错误为“Undefined index:thisUser.Value in ... / keypadapp / code.php”。 任何人都可以帮我吗?提前谢谢......
答案 0 :(得分:0)
尝试将$_GET['thisUser.value']
中的$_GET['thisUser_value']
更改为$_GET
点,并将$_POST
转换为PHP中的下划线。有关详细信息,请参阅此https://stackoverflow.com/a/68742/589909
<强>更新强>
仔细研究你的代码,就像你正在做的那样,无法在php中获取对象的javascript值。我假设thisUser
是一个对象。因此,当将其作为参数传递时,其属性将单独发布到服务器。因此,如果它有一个名为foo
的属性,你会得到它。 $_GET['foo'];
您也可以转储获取请求以查看发送的内容。 var_dump($_GET);
答案 1 :(得分:0)
将param值分配给ajax调用中的变量:
Ext.Ajax.request({
url:'http://localhost/sencha2011/keypadapp/code.php',
params: 'thisuser='+thisUser,
然后在php中,访问值:
$insert = "INSERT INTO codetable(password) VALUES ('".$_GET['thisuser']."')";