SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery $.post problem.

    Hi,
    Anyone have idea why is not this alerting the echo I do in the ajax_template_history.php page? I have on a link onclick="getCheckedIds();" call.

    Code:
    <!-- jQuery -->
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    
    <script type="text/javascript">
    function getCheckedIds()
    {
    /*
        var values = new Array();
        $.each($("input[@name='ids[]']:checked"), function() {
            values.push($(this).val());
        });
    */
        //alert(values);
    
        $.post('ajax/ajax_template_history.php', function(data){
            alert("Data loaded: " + data);
        });
    }
    </script>

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From 1.3 onwards jQuery stopped supporting XPATH attribute selectors. Instead of [@name=something] it should just be [name=something]...
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okey thanks for that! But still does not explain whats wrong in the $.post() -part because nothing happens. And the upper thing is anyway commented out from this example..

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AFAIK. the second parameter is the data to be sent to the server rather than the callback function. So just put {} as second parameter something like this:
    Code javascript:
    $.post('ajax/ajax_template_history.php', {}, function(data){
    	alert("Data loaded: " + data);
    });

    For more details see: http://docs.jquery.com/Ajax/jQuery.p...tacallbacktype
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I actually have some data to send to server also. And this is the way I tried it before and accidentially removed the whole parameter when I took off the data to be sent. So still no go and I dont get either any kind of errors. More ideas?

    edit: heres to code it used to be, but didnt work
    Code:
    <script type="text/javascript">
    function getCheckedIds()
    {
        var values = new Array();
        $.each($("input[name='ids[]']:checked"), function() {
            values.push($(this).val());
        });
    
        alert(values);
    
        $.post('ajax/ajax_template_history.php', { ids = values },  function(data){
            alert("Data loaded: " + data);
        });
    }
    </script>

  6. #6
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okey so I just tested on document ready this same $.post and there it works..
    Code:
        $.post('ajax/ajax_template_history.php', {},  function(data){
            alert("Data loaded: " + data);
        });
    So this has to have something to do with my links or? The links are like this:
    Code:
    <a href="index.php?page=template_history&p=1&sort=name" onclick="getCheckedIds();">something</a>

  7. #7
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem solved, heres the working code. Maybe it would be more appropriate to save these values in cookie instead of session to avoid ajax calls.

    Code:
    function getCheckedIds()
    {
        var linkHref = $(this).attr('href');
        var values = new Array();
        $.each($("input[name='ids[]']:checked"), function() {
            values.push($(this).val());
        });
    
        alert(values);
    
        $.post('ajax/ajax_template_history.php', { 'test[]' : values },  function(data){
            alert("Data loaded: " + data);
            document.location = linkHref;
        });
        return false;
    }


Bookmarks

Posting Permissions

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