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 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    jQuery Ajax: change php function perameter

    code updated below... should have put it here I know
    Last edited by surreal5335; 08-02-2011 at 06:42 AM.

  • #2
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Ok I made adjustments and went with a $.get() for the ajax.

    I am trying to pass in the jquery variable of id through to my php file.

    Here is how I am sending the variable:

    Code:
    function show_post(id)
    {
    
    	$.get('ajax_post.php', { post: id}, function(data)
    	{
    		$('.get_post_container').html(data)
    	});
    	
    }

    Here is how I am trying to get the variable to process in php:


    $id = $_GET[id];


    I have also tried:

    $id = $_GET[post];


    any ideas on how to pass it properly?

    Thanks

  • #3
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You passed it properly but you need to quote the parameter name
    Code:
    $id = $_GET["post"];

  • #4
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Thanks for the reply,

    I made the changes in my php file. I tried click event and nothing happened still. I belive it maybe how I am trying to add the parameter to the javascript function call in my <a>

    onClick="show_post(<?php echo $i; ?>);"

    Firebug shows that the proper value is in place. I did an alert(); in my show_post() but it would not fire.

    I got rid of the php variable and all the associated parameters in my javascript along with the $.get(), alert() still would not fire.

    Could this be bc I have href="javascript:void(0);"?

    I appreciate the help

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    show_post() as posted above seems to be fine. If it is not fired at all, usually there is a Syntax Error somewhere else(!) in your javascript. Every single Syntax Error anywhere in your Javascript code will prevent any javascript from running, even if it is correct by itself. Please check the console in Firebug. If you don't see any error, please set a breakpoint somewhere and see if it is being reached.

  • #6
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Thanks for the suggestion, I narrowed things down and now I got the function to fire and take in the parameter.

    Here is what I have now
    Code:
    $('.show_post').click(function()
    	{
    		var id = this.id;
    		alert(id);
    		// $.get('ajax_post.php', { post: id}, function(data)
    		// {
    			// $('.get_post_container').html(data)
    		// });
    	});
    All the code commented out currently does not work, no errors are being reported either.

    Any ideas?

  • #7
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Are you sure that ajax_post.php is in the same folder as the current HTML document and that you really have at least one element with class="get_post_container"? Otherwise that piece of code seems to be just fine.

  • Users who have thanked devnull69 for this post:

    surreal5335 (08-04-2011)

  • #8
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Thanks a lot, it was the file path for the php that was wrong.


  •  

    Posting Permissions

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