问题
I thought i could use
$this->get('element_id')
to get the value of each DOM-Element in a Ajax-Function. But that doesn't work. Only Post-Elements i can get this way, right? But how do i get other Elements?
Thanks for your help...
This is my Ajax-Class:
class Name_Component_Ajax_Folder_Ajax extends Phpfox_Ajax
{
public function test(){
$iChildItemId = $this->get('element_id');
var_dump($iChildItemId);
$this->html('#testdiv', $this->getContent());
}
}
By clicking a link i call this function ( test() ) and i want to get the value of an input-field (elemnt_id)
回答1:
Basically, you have 2 common solutions to pass a value in an AJAX request that Web browse (Firefox, Chrome, ...) sends to server.
If you are using POST request, you should specific your expected value as a hidden input <input type='hidden' id='val1' value='value_you_want_to_pass_to_sever'>
.
If you are using GET request, you can pass it by using URL param for ex: www.youserver.com?val1=value_you_want_to_pass.
You can get value you want to pass by using JQuery.
Then you can use $this->get('val1') to get your value at server side.
回答2:
This should work to set an element:
$this->call('$(\'#js_photo_category_' . $aCategory['parent_id'] . '\').attr(\'selected\', true);');
The same can be used to get a value
$elementVal = $this->call('$(\'#js_photo_category_' . $aCategory['parent_id'] . '\').val();');
The best way is to use javascript in client side to get the id's using a foreach, save them in an array/json and send them in the request, then do something when done:
$.ajaxCall('module.function_name', 'arrayData='+myArray).done(function(data) {
javascript_function(data);
});
Hope this helps
来源:https://stackoverflow.com/questions/14236962/how-to-get-any-dom-element-by-ajax-in-phpfox