0

So I have the code below. Holder1/Holder2 are just there to see if setting the values to a variable works

jQuery.each(substr, function() {
 if ($('div#'+this+' div.widgetcontent iframe').attr("src")!=undefined) {
    //alert('Widget iFrame: '+$('div#'+this+' div.widgetcontent iframe').attr("src"));
    //alert('Report URL: '+$('div#'+this+' div.widgetcontent iframe').contents().find('iframe').attr("src"));
    var holder1 = 'Widget iFrame: '+$('div#'+this+' div.widgetcontent iframe').attr("src");
    var holder2 = 'Report URL: '+$('div#'+this+' div.widgetcontent iframe').contents().find('iframe').attr("src");
    $.post("functions/process.asp", 
    { 
        widget: $('div#'+this+' div.widgetcontent iframe').attr("src"), 
        iframe: $('div#'+this+' div.widgetcontent iframe').contents().find('iframe').attr("src")
    } 
    , function(data) {
    alert("Data Loaded: " + data);
     }
);
}

However the iframe value is not posted. However instead of using holder1/holder2, if I were to use the following instead, it all works

alert('Widget iFrame: '+$('div#'+this+' div.widgetcontent iframe').attr("src"));
alert('Report URL: '+$('div#'+this+' div.widgetcontent iframe').contents().find('iframe').attr("src"));

Obviously I don't want it alerting each time so was wondering what was happening?

I've basically implemented a dashboard where people can add widgets and then move them up or down. There is one there by default. If I add another (becomes second) and then move it to the first position, it gives a blank value. If I move it back to second, it works.

[EDIT]

In fact, if I just use alert(''); then it works just fine!!!

j08691
  • 204,283
  • 31
  • 260
  • 272
pee2pee
  • 3,619
  • 7
  • 52
  • 133

2 Answers2

0

I think, the problem is that you use "this" in the ajax-request. try to save it to a variable before and use it

jQuery.each(substr, function() {
var myobject=this;
        if ($('div#'+myobject+' div.widgetcontent iframe').attr("src")!=undefined) {
            var holder1 = 'Widget iFrame: '+$('div#'+myobject+' div.widgetcontent iframe').attr("src");
            var holder2 = 'Report URL: '+$('div#'+myobject+' div.widgetcontent iframe').contents().find('iframe').attr("src");

            $.post("functions/process.asp", 
            { 
            widget: $('div#'+myobject+' div.widgetcontent iframe').attr("src"), 
            iframe: $('div#'+myobject+' div.widgetcontent iframe').contents().find('iframe').attr("src")
            } 
            , function(data) {
                alert("Data Loaded: " + data);
             }
             );
        }
Dirty-flow
  • 2,306
  • 11
  • 30
  • 49
  • No luck I'm afraid. When I change the widget/iframe to `widget: holder1, iframe: holder2` I get the message that holder 2 is undefined. – pee2pee Sep 17 '12 at 10:37
  • can you post your HTML, i think it's possible that your jquery selector is the problem – Dirty-flow Sep 17 '12 at 10:40
  • It gets the SRC of the iFrame fine so not sure why it's not getting the SRC of the iFrame within that iFrame?!? `
    ` If I leave the alerts in, it works just fine!!!
    – pee2pee Sep 17 '12 at 10:43
0

I put a delay straight after stop: function(event, ui) { of 1 second which seems to sort it

pee2pee
  • 3,619
  • 7
  • 52
  • 133