Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pass an attribute from JQuery to PHP (on event)?

    Hello, first I want to point that I'm using jQWidgets.
    I want to pass an attribute from jquery to a PHP file. Now, I've tried using $.post.
    Like this:

    Code:
    $('#problemiTree').bind('select', function (event) {
                        var item3 = $('#problemiTree').jqxTree('getSelectedItem');
                        if (item3 && item3.parentId!=0)
                            dataAdapter4.dataBind();
                        $.post( 
                        "problemiOblastData.php",
                        { selectedItem: item3.label }
                        
    
                    );
    In the PHP file I test with:

    Code:
    if (isset($_GET['selectedItem:']))
        echo 'no';
    else
        echo 'yes';
    And it always gives "no".

    Please help,
    thank you.

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    well no one else answered so I took a look. Looks to me like $('#problemiTree').jqxTree('getSelectedItem'); returns an array, and I'm pretty sure .label only works on form elements, so maybeyou jsut need to remove the .label?

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've tried that and I have modified the code in php like so (it was not correct):
    Code:
    if (isset($_POST['selectedItem']))
        echo 'yes';
    else
        echo 'no';
    My problem remains ('no' again), but thanks anyway.

    EDIT: Maybe I'm not testing correctly. I use a direct link to the php file to check echo.
    I've tried using $.ajax, but the result is the same. Is there maybe another way for me to pass data to php?
    Last edited by branko7171; 10-27-2012 at 11:44 AM.

  • #4
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    SOLVED
    I've figured out what was the problem. I passed item.label (or item), where I should have passed item.id. mySQL query in the php file requires that id, and it won't work with label etc...


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •