this is probably something very simple and i'm just making it more difficult than it has to be. i have a php page, which just has a checkbox and a button. when i click the button it should call my "collection.php" page and then update my index page on the status. i took out most of my code in collection.php and my index page still doesn't update. what am i doing wrong?? thanks in advance!
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
// Click trigger for image
$("#myBtn").click(function() {
if ($('#update').is(":checked"))
var update = 'on';
else
var update = 'off';
$.ajax({
url: 'collection.php',
type:'POST',
dataType: 'json',
data: 'update='+update,
cache: false,
async: false,
success: function(output_string){
//alert(JSON.stringify(output_string));
$('#collection_status').html(''); // Clear #wines div
$('#collection_status').append(output_string.worked + '<br/>');
}, // End of success function of ajax form
error: function() {
alert("there is an issue with the collection!");
}
}); // End of ajax call
return false; // keeps the page from not refreshing
});
});
</script>
</head>
<body style="background-color:#333333;color:white;font-family:verdana;text-transform:lowercase;">
<form>
<input type="checkbox" id="update" /> Update Existing<br />
<button id="myBtn">Collect</button>
</form>
<br />
<div id="collection_status"></div>
</body>
</html>
collection.php
<?
// movie search variables
$dir = "/video/Movies/";
$movie_extensions = array('mkv','mp4','m4v','avi');
$update_movies = 0;
if(isset($_POST["update"]))
$update_movies = $_POST["update"];
// read contents from $dir
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
$file_info = pathinfo($file);
$output_string['worked'] = 'found <span style="color:yellowgreen;">' . $file . '</span><br />';
echo json_encode($output_string);
}
closedir($dh);
}
}
when i remove the echo portion from the collection script i receive a response (below works):
$output_string['worked'] = 'testing';
echo json_encode($output_string);
once i add that back to the loop it errors.
as a test i added a for loop in there - it also fails:
for($i=0;$i<10;$i++)
{
$output_string['worked'] = 'found <span style="color:yellowgreen;">' . $file . '</span><br />';
echo json_encode($output_string);
}
console.log(output_string);
the results and post it please? – We0 Aug 16 at 14:45