Can I Get Realtime Php Data To Appear In A Jquery Dialog Box?
Solution 1:
Use jQuery.get()
to request your PHP page, getScript
is for loading javascript files.
$.get('yourpage.php', {}, function(data, status, xhr) {
// all done, get your content from the data variable.
});
If you show your popup in the body of the get call instead of calling the get from the dialog then the dialog will show after it has all the data.
EDIT: AJAX seems to wait for readyState 4 before displaying any information. PHP flush seems to send a readyState of 3. You will need to listen for that and fill in the responseText.
There are a few potential bugs that may require disabling compression and setting the content type to application/octet-stream.
Solution 2:
You can do this the way you are doing it except you need to use the done function for jQuery's getScript.
http://api.jquery.com/jQuery.getScript/
I prefer using their ajax function
http://api.jquery.com/jQuery.ajax/
If you need it to update setup a js interval/timeout
Solution 3:
As suggested I am marking down my work around as an answer to this question so that others may benefit from this.
First I added an iFrame to the dialog box in the index.html:
<div id="pwrShellDiagWC" style="display: none;">
<iframe id="ajaxFrameWC" src="" width="100%" height="60%"; frameborder="0"></iframe>
</div>
Then in Javascript (using jQuery) I initialized this dialog box adding code to the "open" option to load the php url into the iFrame:
$('#pwrShellDiagWC').dialog({
autoOpen: false,
width: 800,
title: "Processing your request",
resizable: false,
modal: true,
open: function(event, ui) {
var frameAttrib = $('#ajaxFrameWC').attr('src');
var phpURL = './cgi-bin/test.php?value1=arg1';
if (frameAttrib) {
// do nothing!
}
else {
$('#ajaxFrameWC').attr('src',phpURL)
}
});
I had some buttons added as well but I don't believe you need to see that for this to work. The test.php uses the code I put in my question and displays line by line in the dialog box.
The only aspect I am working out now is to force the iFrame to stay scrolled at the bottom but I am sure a few well placed searches will get my past that small hurtle.
Cheers, Hope this is helpful to some!
Solution 4:
I meet the same problem, as my search result, you can use XMLHttpRequest.
<html><head><scripttype="text/javascript"src="jquery-1.11.3.js"></script><scripttype="text/javascript"language="javascript">functionchangeText() {
var xhr = newXMLHttpRequest();
xhr.open('GET', '/test.php', true);
xhr.send(null);
var timer;
timer = window.setInterval(function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
window.clearTimeout(timer);
$('body').append('done <br />');
}
$('#phanxMessage').html(xhr.responseText);
console.log(xhr.responseText);
}, 1000);
}
</script></head><body><inputid="submit"onclick="changeText();"type="button"value="Get PHP Response"/><textareaid="phanxMessage"rows="30"cols="100"></textarea></body></html>
Post a Comment for "Can I Get Realtime Php Data To Appear In A Jquery Dialog Box?"