Get remote <iframe> content...

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

Locked
David de Argentina
Posts: 1596
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina
Contact:

Get remote <iframe> content...

Post by David de Argentina »

Hi all,

this PHP shows the ip of your machine:

http://soporte.byethost7.com/ip.php

I can see the <iframe> within the neoapp, and the content.

I need catch the content of this iframe and put it into an alert(...), but nothing works...

Any ideas ?

Thanks in advance,
David de Argentina
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Get remote <iframe> content...

Post by Gaev »

David de Argentina:
Any ideas ?
You don't need to use the < iframe > element ... here is some code I attached to a Push Button's click event ...

Code: Select all

BeginJS
$('#Container2').html("wxyz");
alert("before .get");

$.get("http://soporte.byethost7.com/ip.php", function(data,status){
   $('#Container2').html(data);
   alert("Data: " + data);
},'text');

gkTemp = "temp";

EndJS
Note that ...

1) you don't need the command ...

$('#Container2').html("wxyz");

... I just use it to observe actual changes during testing.

2) the command ...

gkTemp = "temp"

... was placed as a workaround (for running as a WebApp) in previous beta of NeoAppBuilder ... don't know if it has been fixed in latest beta.


With this code, I got the expected returned data.
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: Get remote <iframe> content...

Post by Neosoft Support »

You shouldn't need gkTemp = "temp" anymore.

The jQuery get command works in Chrome but for some reason it doesn't do anything in IE. No response, no error messages, nothing.
NeoSoft Support
David de Argentina
Posts: 1596
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina
Contact:

Re: Get remote <iframe> content...

Post by David de Argentina »

WOW !!!

Beautiful ! Beautiful ! Beautiful ! Beautiful ! Beautiful ! Beautiful ! Beautiful ! Beautiful !

Thanks !
David de Argentina
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Get remote <iframe> content...

Post by Gaev »

Dave:
You shouldn't need gkTemp = "temp" anymore.
Thanks for the update ... I will remove all such work arounds from my Test App
The jQuery get command works in Chrome but for some reason it doesn't do anything in IE. No response, no error messages, nothing.
Good to know ... BTW, works in Firefox too.
David de Argentina
Posts: 1596
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina
Contact:

Re: Get remote <iframe> content...

Post by David de Argentina »

if you need wait for complete file download, in order to process the returned data, you must turn off the asynchronous (default) mode of $.get

The trick is:

Code: Select all

jQuery.ajaxSetup({async:false});
$.get(...);
jQuery.ajaxSetup({async:true});
This is not ellegant, and the debug console should tell you a warning message, but is very effective.

My 0.01
David de Argentina
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Get remote <iframe> content...

Post by Gaev »

David de Argentina:
if you need wait for complete file download, in order to process the returned data, you must turn off the asynchronous (default) mode of $.get
Not sure what you are talking about ... if you use ...

Code: Select all

$.get("http://soporte.byethost7.com/ip.php", function(data,status){
   $('#Container2').html(data);
   alert("Data: " + data);
},'text');
... aren't the commands within the function (data,status){...} i.e. ...

Code: Select all

   $('#Container2').html(data);
   alert("Data: " + data);
... serviced AFTER the download is complete ?
David de Argentina
Posts: 1596
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina
Contact:

Re: Get remote <iframe> content...

Post by David de Argentina »

Hi Gaev,

Figure you need get some values from your received data with something like getElementById... or similar.

If you put this stament ...getElementById inmediatly after the $.get() function, the most probabily is you get an error message, because data could be dowloading at this time.

As $.get() is an asynchronous function, inmediatly returns the control to the next action, and, at this moment, you does not have the data.

Pretty confuse ?
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Get remote <iframe> content...

Post by Gaev »

David de Argentina:

1) regarding the use of async:false ...

On this page http://api.jquery.com/jquery.ajax/ ... it says that ...
As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().
... and on this page http://stackoverflow.com/questions/1478 ... query-ajax ...it says that ...
Remember that this also means that browser will not capture/trigger any events happening while ajax is being executed. I found this out the hard way, trying to figure out why Firefox was not triggering a click event. It turned out to be because of a "forced" blur event with a following sync call blocking it.
... and on this page http://stackoverflow.com/questions/8929 ... move-event ... it says that ...
This code stops mousemove event
async:false halts the browser, all JavaScript, until it's done
2) I didn't invent the command syntax for this AJAX stuff (and jQuery's $.get() is just a layer on top of AJAX) ... but they chose this difficult (for some) to understand syntax for specifying the "callback function" i.e. "what to do when the requested data is made available" ... in your example, if getElementById is to be performed AFTER the data is received, you would do something like this ...

Code: Select all

$.get("http://soporte.byethost7.com/ip.php", function(data,status){
   //your getElementById stuff goes here
},'text');
If you find this type of coding difficult to read (especially when you start nesting Asynchronous commands), you can place "the code to be serviced when the requested data is received" in a separate function like this ...

Code: Select all

function doThisUponReceiptOfData(data,status) {
   //your getElementById stuff goes here
}

$.get("http://soporte.byethost7.com/ip.php",doThisUponReceiptOfData ,'text');
Locked