AJAX - passing values back from PHP scripts using echo()
I have a wierd problem (wierd to me as a noobie that is)...
and a document.getElementById('hw').innerHTML = response; statement puts the string value between <div> tags in the html page.
Simple. However, I've found that if the PHP tries to either echo a string directly:
echo "Hello World";
or assign it to a variable first and then echo the variable:
$x="Hello World"; echo "$x";
However, if the string is stored in a .txt file, and I retrieve it from the file, assign it to a variable, and then echo the variable, it works!
The same thing happens with numbers.
So whenever I want to assign a value to a variable and send it back, I have to store it in a file first, then retrieve it and echo it. There must be a better way. How do I just send the value stright back
Without seeing any code I can't specify the exact problem but it's mostly likely to be with the PHP code. It would explain why the text file works.
If there are no errors it might be that the code you want isn't being run. If it's in a function, is the function being called? If it's called through an if statement, is the condition being met?
If you have any ifs in your PHP, add elses to them to try and catch any errors.
Here's the PHP code I was experimenting with in its entirety. There are no if statements. Also, for what its worth there are no html tags around it.
$r = "changedetect1.txt";
$open = fopen($r, "r");
//echo "hello world";
changedetect1.txt has a single value or a string stored in it.
echo "$x" works.
However if I comment out the echo "$x" statement and un-comment any of the statements below it, nothing happens.
If I just run the PHP program by itself, just by typing its URL into the browser, it works fine - all the echo statements work.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)