How to get any DOM Element by Ajax in PHPFox

此生再无相见时 提交于 2020-01-06 13:45:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!