2013-01-21 22 views
2

我的看法包含以下代碼到PHP得到錯誤,當我通過Ajax請求發送文本字段值使用煎茶觸摸

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()); 
} 
?> 

這裏即時得到錯誤的「未定義指數:thisUser.Value在.../keypadapp/code.php」上線5 誰能幫我?在此先感謝...

回答

0

分配參數值的方式來變量在Ajax調用:

   Ext.Ajax.request({ 
        url:'http://localhost/sencha2011/keypadapp/code.php', 
        params: 'thisuser='+thisUser, 

然後在PHP中,訪問該值:

$insert = "INSERT INTO codetable(password) VALUES ('".$_GET['thisuser']."')"; 
+0

感謝卡蘭Punamiya,它的工作 – jimmy

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);

+0

感謝您的答覆brenjt,但不幸的是我仍然得到同樣的錯誤。 – jimmy