I would like to do a fancybox prompt out to upload image, i have use iframe to solve the page refresh after onSubmit but i still need to update some info at layout, can anyone tell me how to change it using ajax so i can use JSON return to update the info inside the success function? Below is my code
The answer is a bit tricky, you need to post to the iframe and then collect the JSON response from its document. This is a modified segment of what it worked for me in the past:
// get old target
var oTarget = form.target;
form.target = "redirect-target"; // new target the iFrame
form.submit();
window.iframeHandler = function () {
var e = $("#redirect-target").get(0);
form.target = oTarget;
try {
response = (e.contentWindow || e.contentDocument || e).document.body.innerHTML;
response = response.replace(/[\f\n\r\t]/g, " ");
if (window.opera) response = response.replace(/"/g, '"')
} catch (f) {
response = null
}
// parse JSON here
response = eval('('+response+')');
if (response.status == 0)
// my JSON object has status property 0 is an error
else {
// otherwise update fields with data with an
// oncomplete function callback
myOncomplete(response.data);
return true
}
};
return true
I have try to follow your way but it doesn’t work. But from the logic it should be work… i think it might be my code prob, below is my code. The alert is just for checking.