1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

[SOLVED] list_X.js cannot post

Discussion in 'Community' started by OndrejH, May 2, 2015.

Thread Status:
Not open for further replies.
  1. OndrejH

    OndrejH Member

    Level: Community
    With the same structure as with form_X.js used for list_X.js I cannot post.

    function newOrderJS(){
    var rowitem = 70;
    var url="index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=neworderphp&rowitem=" + rowitem;
    var response = '';

    new Request(
    { url: url,
    method: 'neworderphp', 'rowitem': rowitem,
    onComplete:function(response){
    if(response !== '') {
    alert(response);
    }
    }
    }).sent();
    }
    Is there any typo here? Any idea where to start searching?
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    Should be
    }).send();
     
    OndrejH likes this.
  3. OndrejH

    OndrejH Member

    Level: Community
    Thank you, Troester. Sorry for the sent typo. That was the only one I do not have in the original script. If there are no other, them I am sure the problem lays somewhere else. (In reality I use the right spelling send. ... The rest of the code is my site original.)
    My point is I do not get any action at all. Even with very simple script in user_ajax.php like this one:

    <?php
    defined( '_JEXEC' ) or die( 'Restricted Access' );
    class userAjax {
    public function neworderphp(){
    $rowitem = JRequest::getVar('rowitem', '');
    echo $rowitem;
    }
    }
    ?>

    ... I get no post, just GET for Fabrik's require.js

    no_POST.png
    I am trying to post product id (rowid in this case) from product listing to inquiry form. I tried php plugin with JS, button with JS however I struggle with two obstacles.
    1st, I am not able to get the LIST rowid for one single row and submit it to be processed by "inquiry.php" (to run sql to insert it to db).
    2nd, suddenly, I am not able to do what was possible with my form_X.js - i.e. to make the script posting to user_ajax.php.
     
  4. OndrejH

    OndrejH Member

    Level: Community
    to get rowid I tried with no success:
    --- 1 ---
    var rowitem = $('hastr_items___id_raw');
    --- 2 ---
    var elementname = "hastr_items___id_raw";
    var myelement = listdata[0][0].data;
    var rowitem = myelement[elementname];
    --- 3 ---
    var rowitem = listdata[0][0].data.hastr_items___id;
    --- 4 ---
    var rowitem = '{rowid}';
    --- also no success ---

    What I have pointed out while working with form_X.js in other part of site was script stopped being executed when I had used standard naming convention for Javascript like: rowItem, newOrderPHP - with Capital letters. Started working againg when I changed to lowercase.

    I did not really finish testing the 4 examples above as I found I possibly do not have this list_X.js javascript posting at all.
     
  5. troester

    troester Well-Known Member Staff Member

    Level: Community
    I don't know what you want to achieve in the end and I'm not good with JS but
    your code is working fine with listJS plugin
    Code (Text):
    var rowitem = ids.join(',');
    var url="index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=neworderphp&rowitem=" + rowitem;
    var response = '';
     
    new Request({
                url: url,
                method: 'neworderphp',
                'rowitem': rowitem,
                onComplete:function(response){
                    if(response !== '') {
                        alert(response);
                    }
                }
    }).send();
    BTW: you shouldn't use JRequest in php, it's still working but deprecated; use
    Code (Text):
    $app = JFactory::getApplication();
    $input = $app->input;
    $input->getString('variablename');
     
    OndrejH likes this.
  6. OndrejH

    OndrejH Member

    Level: Community
    Thank you very much Troester. Finally I am able to move ahead.
     
  7. OndrejH

    OndrejH Member

    Level: Community
    the problem was with:
    $rowitem = JRequest::getVar('rowitem', '');

    As you suggested, works with:

    $app = JFactory::getApplication();
    $input = $app->input;
    $myrow->getString('itemrow','');
     
  8. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Are you sure that's correct? That third line, with $myrow, doesn't look right if you are trying to fetch a query string input from $input.

    -- hugh
     
    OndrejH likes this.
  9. OndrejH

    OndrejH Member

    Level: Community
    Sorry, Hugh, you are right. This is exactly what worked.
    $myrow->$input->getString('itemrow','');

    I am still struggling to get element value of particular row.
    Can I get that with list php plugin via javascript code there?
    It seems I do not clearly understand what is the difference between javascript of this php plugin and usage of list_X.js.
    I assume javascript in the php list plugin should work with element values of particular rows. However I have not found any solution to get the element value in javascript this way yet.
    Sorry for bothering you with this one. I am missing something what is possibly already described somewhere in wiki.
     
  10. OndrejH

    OndrejH Member

    Level: Community
    Of course, I have tried to use list_X.js with

    var rowitem = ids.join(',');

    however got an "undefinied" error.
     
  11. OndrejH

    OndrejH Member

    Level: Community
    With help from Matthias I was able to figure out the way the list table data are declared as:

    var listdata = Fabrik.getBlock('list_123').options.data;
    var rowitem = listdata[0][0].data.table___element;

    With javascript from list php plugin I get value "1" which is of course correct because that is the value of the 0 in array. I get the first row value. So still not able to pick value of particular button related row.
     
  12. OndrejH

    OndrejH Member

    Level: Community
    Okey, one non-sense I did was combining the php plugin and js code instead of using just purely javascript list plugin.
    Please do not waste your time on this topic. I will let you know when I figure out.
     
  13. OndrejH

    OndrejH Member

    Level: Community
    yo soy estupido. Of course, super simple. I do not know where did I pick up that idea to use the php plugin with javascript insted of purely javascript plugin.
    Maybe just tired of working on the weekend.
    The only correct way was to use JS List plugin with following code to call php function inside user_ajax.php:
    Code (Text):
    var rowitem = ids.join(',');
    console.log(ids);
        var url="index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=neworderphp&rowitem=" + rowitem;
        var response = '';
     
        new Request(
      { url: url,
        method: 'neworderphp', 'rowitem': rowitem,
            onComplete:function(response){
                if(response !== '') {
            alert(response);
    }
            }
        }).send();
     
  14. OndrejH

    OndrejH Member

    Level: Community
    Thanks a lot again for your help and patience hugh (and also Matthias mudshark79) :)
     
  15. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Glad you got it sorted out.

    -- hugh
     
  16. OndrejH

    OndrejH Member

    Level: Community
    Thank you, hugh
     
Thread Status:
Not open for further replies.

Share This Page