Search code examples
jquery-uijquery-postjquery

Value only gets set when using alert()


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!!!


Solution

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