0

What i want to do:

I want to, through a cross-domain pick a number from a php page and then with jquery use this as height on an iframe. page.php for an example outputs: 195

This is what i've done:

$(document).ready(function() {
            $.get("http://domain.com/page.php", function(data){
                $('#Myiframe').attr("height", data + "px");
            });
        });

And this works great in chrome, firefox and safari but not (i think you've guessed it) in IE 7/8 (don't have 9). Is there something about crossdomain protocol? I use this on my php page:

    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Headers: x-requested-with");

Does anyone know why this doesen't work in IE ?

Paparappa
  • 2,099
  • 3
  • 18
  • 35
  • 1
    We had the same issue 1 year ago, at this time IE's XDomainRequest wasn't supported in jQuery, maybe it's still not supported(can't tell you) http://stackoverflow.com/questions/6318996/jquery-getjson-not-working-properly-in-ie8-with-gdata-json-c-why/6320496#6320496 . But related on the last comment there(1 month ago) I guess it still isn't. – Dr.Molle Mar 30 '12 at 09:57

2 Answers2

1

Check whether you get any value in data or any cross-domain error in the console.

If everything goes great, then use:

$('#MyIframe').css('height', data + 'px');
codef0rmer
  • 10,284
  • 9
  • 53
  • 76
0

A less elegant but more sturdy solution is to use JSONP to avoid using XMLHttpRequest at all.

Suppose the API call is a function like num_votes(id), you would call it by injecting a tag like <script src="http://example.com/jsonp.php?m=num_votes&id=123"></script>.

The body of this script would then call a function of your choosing. As you'd have to use a global callback function, you should set up a callback registry, so your JSONP API would return something like myCallbacks[$ID]({votes: 1234});

<script>
  my_callbacks={};
  on_ready(
    qid = 'q'+Math.floor(Math.random()*(1<<16));
    tag = create_element('script')
    tag.src = api_url + 'jsonp=my_callbacks.'+qid;
    my_callbacks[qid] = function(o) { alert('votes: ' + o.votes); };
    body.append(tag);
  );
</script>
lericson
  • 1,318
  • 1
  • 12
  • 22