2011-10-07 64 views
0

我有這樣的電話:意外的關鍵

bindAutoComplete('pro_title'); 

使用這個功能進行jQuery的AJAX調用:

function bindAutoComplete(id) { 
    $("#" + id).keyup(function() { 
     if (this.value.length > 1) { 
      $.post("/ajax/autocomplete" , {id: this.value }, function(data) { 
       // do stuff here... 
      }); 
     } 
    }); 
} 

,與此PHP腳本:

public function autocompleteAction() 
{ 
    if ($this->getRequest()->isPost()) { 
     echo print_r($this->getRequest()->getPost()); 
    } 
} 

當我運行這些腳本時,PHP回聲:

Array ([id] => test) 1 

這裏的'測試'是來自AJAX調用的this.value中的值。

我在找什麼是[id]將被替換爲pro_title

請幫忙!

+1

你是什麼意思?只需用'{pro_titile:this.value}'替換'{id:this.value}'' –

+0

'爲什麼你有'echo print_r('?這裏你不需要'print_r',這是毫無意義的。 –

+0

@Rocket因爲我正在測試print_r沒有生產 – tjb1982

回答

3

的{ID:THIS.VALUE}應該是{ID:ID} ..

function bindAutoComplete(id) { 
    $("#" + id).keyup(function() { 
     if (this.value.length > 1) { 
      $.post("/ajax/autocomplete" , {id: id }, function(data) { 
       // do stuff here... 
      }); 
     } 
    }); 
} 

如果你要發送的價值,以及你可以做{ID:ID,值:此.value的}

+0

哇,謝謝 – tjb1982

1

你的意思是這樣的:

function bindAutoComplete(id) { 
    $("#" + id).keyup(function() { 
     if (this.value.length > 1) { 
      $.post("/ajax/autocomplete" , {id: id }, function(data) { 
       // do stuff here... 
      }); 
     } 
    }); 
}