5 Replies - 2188 Views - Last Post: 05 September 2012 - 12:59 PM

#1 Cpp_noob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 06-July 09

JavaScript reading PHP data

Posted 05 September 2012 - 07:52 AM

im trying to read data from php but in firefox im getting the element not found error
the code is very simple , since im new to javascript and php

Javascript code:
function ShowPage3()
{
	window.location="#Page3"
		
	$.get('test.php?name', function(data) 
	{
    	$('#ccc').html(data);
	});

}


PHP code:
<?php
	if (isset($_GET['name']))
 	{
		header("HTTP/1.0 200");
    	echo "Asked for name!";
	}
?>


Is This A Good Question/Topic? 0
  • +

Replies To: JavaScript reading PHP data

#2 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 6233
  • View blog
  • Posts: 10,782
  • Joined: 28-September 07

Re: JavaScript reading PHP data

Posted 05 September 2012 - 07:59 AM

View PostCpp_noob, on 05 September 2012 - 10:52 AM, said:

$.get('test.php?name', function(data) 



I believe this is your problem.

In your PHP, you're trying to $_GET['name']. In order for that to work, you would have to use test.php?name=xyz. Otherwise, you're not giving anything for $_GET to actually get.
Was This Post Helpful? 0
  • +
  • -

#3 Cpp_noob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 06-July 09

Re: JavaScript reading PHP data

Posted 05 September 2012 - 08:13 AM

hey BenignDesign

i still get "no element found" on line 7 of the php


i dunt know if this is trivial but its a jquery mobile app
Was This Post Helpful? 0
  • +
  • -

#4 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 6233
  • View blog
  • Posts: 10,782
  • Joined: 28-September 07

Re: JavaScript reading PHP data

Posted 05 September 2012 - 08:48 AM

Line 7 of your Javascript is
$('#ccc').html(data);




I'm afraid I'm not entirely familiar with jQuery - particularly using $, so maybe help me understand what you're doing with this... looks like you're passing the color code #ccc to an html string thing. Am I even close?
Was This Post Helpful? 0
  • +
  • -

#5 Cpp_noob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 06-July 09

Re: JavaScript reading PHP data

Posted 05 September 2012 - 08:55 AM

$('#ccc').html(data);
will change the text of the id element (in this case the id is 'ccc') to whatever the "data" holds

also if i remove that line i still get the same error

This post has been edited by Cpp_noob: 05 September 2012 - 08:55 AM

Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: JavaScript reading PHP data

Posted 05 September 2012 - 12:59 PM

doesn’t line #3 reloads the page before the AJAX can return?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1