0

Could anyone just help me out with this. I'm trying to get my AJAX to simply echo what's in my php file when a click a link:

AJAX:

$(document).ready(function(){

	$("#gentest").click(function(e){

		e.preventDefault();

		$.getJSON("char_con.php?", {act: 'char_con'}, function(data){

			$(".x").html(data);
		});
                                        

	});
                                
                                
});


                <div class="box">
                        <a href="#" id="gentest">Generate Quote</a>
                        <div class="x">TEST</div>
                </div>

my PHP file:

<?php
		if($_GET['act'] == "char_con") {
		
		$strA ='
		<div id="dark_ad"><img src="img/data/under_ad.png" alt="Click here to begin"></div>
		<div id="con_sep"></div>
		'; 
		}  
		else 
		{
		$strB =' 
		<a href="index.php?act=gen_con"><img src="img/vpbg/vpbgt.png" alt="Click here to begin"></a>
		';
		}
?>

I'm pretty sure I have the AJAX bit down but would anyone tell me how to get it to actually echo the php? I'm a bit lost.

Thanks for any help.

Edited by ello: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ello
1

Ello,

The PHP doesn't actually output anything, and what you want to be output isn't JSON encoded.

Try:

<?php
	if($_GET['act'] == "char_con")
	{
		echo '<div id="dark_ad"><img src="img/data/under_ad.png" alt="Click here to begin"></div><div id="con_sep"></div>';
	}
	else
	{
		echo '<a href="index.php?act=gen_con"><img src="img/vpbg/vpbgt.png" alt="Click here to begin"></a>';
	}
?>

and

$(document).ready(function(){
	$("#gentest").click(function(e) {
		e.preventDefault();
		$.get("char_con.php?", {act: 'char_con'}, function(data) {
			$(".x").html(data);
		});
	});
});

Airshow

0

Ahhh of course, stupidly overlooked the fact I was using $str. Thanks for the fix, worked perfectly (:

Thanks a lot, appreciate it.

+1 for your help. (:

Ello.

Edited by ello: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.