I have a form that uploads a file in firame to a remote server. As a result, upon presentation, the url server returns json data with the result of the operation that my iframe catches.
{'result': 'true' or 'false'}
Now I would like to get this json as a callback to my iframe. I know that I need jsonp for this because it is a cross site. Here is my function with sample code from the IBM website :
function fileUploadFunction(){ var fileUploadForm = $('#file_upload_form'); fileUploadForm.attr('action', uploadURL); fileUploadForm.submit(); $('#upload_target').load(function () { alert("IFrame loaded"); $.getJSON(uploadUrl+"&callback=?", function(data) { alert("Symbol: " + data.symbol + ", Price: " + data.price); }); }); };
But here there are several problems. At first - my uploadUrl - it's just "http: // something /". Do I need this to support calls with the suffix $callback= ?
Secondly, the server gives an answer only as a result of the file upload. So I need to get the result, which is stored in my iframe, and not at the specified url. How to solve this?
Here is the link. Pay attention to the hidden iframe inside the form. The result from the server appears.
http://ntt.vipserv.org/artifact/
EDIT
I have already tried:
$('#upload_target').load(function () { var ret = frames['upload_target'].document.getElementsByTagName("body")[0].innerHTML; var data = eval("("+ret+")"); });
But it causes a permission error.
javascript jsonp cross-domain iframe response
mastodon
source share