I am attempting to access the value echoed by my php file using jquery. I am running this on an apache server. My code is
My PHP (findjson.php) file is:
<?php
foreach (glob("*.json") as $filename)
echo $filename;
?>
Part of my Javascript/html file
...
<script id='code-js' type="text/javascript">
$(document).ready(function(){
$.get("findjson.php", function(data) {
alert(data); //uncomment this for debug
$('#showdata').html(data);
}, 'text');
});
...
function load(){
var docname = $('#showdata');
Scene.loadObject(docname);
}
I would like docname in the function load to be set to data. I am unsure on how to proceed though, have tried a variety of ways, and am out of ideas. I am trying to follow this tutorial: http://www.tutorialspoint.com/jquery/ajax-jquery-get.htm . I tried using global variables, but for some reason, global variables don't seem to work well in the function(data) (I assume because it is a call back function). I also tried using a this.data = data line in the function but that didn't seem to work very well either.
I think what you want to do is:
$(document).ready(function(){
$.get("findjson.php", function(data) {
alert(data); //uncomment this for debug
Scene.loadObject(data);
//or you could do
$('#showdata').data('scenedata', data);
}, 'text');
});
function load(){
var docname = $('#showdata').data("scenedata")
Scene.loadObject(docname);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.