Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-02-2011, 05:46 AM   PM User | #1
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
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..
surreal5335 is offline   Reply With Quote
Old 08-02-2011, 06:41 AM   PM User | #2
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
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
surreal5335 is offline   Reply With Quote
Old 08-02-2011, 10:46 AM   PM User | #3
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You passed it properly but you need to quote the parameter name
Code:
$id = $_GET["post"];
devnull69 is offline   Reply With Quote
Old 08-03-2011, 06:00 AM   PM User | #4
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
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
surreal5335 is offline   Reply With Quote
Old 08-03-2011, 10:48 AM   PM User | #5
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Old 08-03-2011, 09:27 PM   PM User | #6
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
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?
surreal5335 is offline   Reply With Quote
Old 08-03-2011, 09:40 PM   PM User | #7
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
surreal5335 (08-04-2011)
Old 08-04-2011, 06:31 AM   PM User | #8
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
Thanks a lot, it was the file path for the php that was wrong.
surreal5335 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:19 PM.


Advertisement
Log in to turn off these ads.