PHP, AJAX and JS

Log in to stop seeing adverts

Status
Not open for further replies.

Matt_B

Well-Known Member
Anyone in here any good with AJAX?

Basically I have a main page, call it index.php, which has a JS function declared, call it Reload(depth,width).

I use AJAX to load a page, call it data.php?id=1

I get the AJAX page to run a DB query and echo "<script type=\"text/javascript\">Reload('" . $data["depthBedding"] . "','" . $data["trenchWidth"] . "');</script>";

For some reason this isn't running the Reload function declared in the main page. Any idea why?!?!

EDIT: It does echo the javascript content into the page correctly, it just doesn't run the function. Do I need to declare it global somehow?
 
Last edited:
I won the league with them on Football Manager :102:
 
Do you have something coded to call the function on the AJAX page?

Maybe something like <body onload="Reload()">
 
Do you have something coded to call the function on the AJAX page?

Maybe something like <body onload="Reload()">

Nope, as the Ajax content is loaded into a div in the page you shouldn't use the <html> or <body> tags
 
Nope, as the Ajax content is loaded into a div in the page you shouldn't use the <html> or <body> tags

Not sure I understand ya.

What I was getting at was that you need an event to trigger the function, for example the page loading.
 
Ajax loads the page content of the second page into a div, mine simply echos a javascript <script> tag that should trigger the Reload function. It doesn't throw an error saying "function cannot be found" which confuses me, because I would expect that if it couldn't find it.
 
For anyone in a similar quandry I figured it out. As it puts my new page content into a div, it clearly isn't going to run a script tag, as it trates it as content.

Doh
 
Status
Not open for further replies.
Log in to stop seeing adverts

Championship

P Pld Pts
1Leicester4697
2Ipswich4696
3Leeds Utd4690
4Southampton4687
5West Brom4675
6Norwich City4673
7Hull City4670
8Middlesbro4669
9Coventry City4664
10Preston 4663
11Bristol City4662
12Cardiff City4662
13Millwall4659
14Swansea City4657
15Watford4656
16Sunderland4656
17Stoke City4656
18QPR4656
19Blackburn 4653
20Sheffield W4653
21Plymouth 4651
22Birmingham4650
23Huddersfield4645
24Rotherham Utd4627

Latest posts

Top