开发者

YUI: Problem in file Upload and processing script..!

开发者 https://www.devze.com 2023-02-11 10:17 出处:网络
I have developed an interface in YUI. In which there is a form to upload a file on submit click. YAHOO.util.Connect.setForm(document.getElementById(\'settings_Form\'),true);

I have developed an interface in YUI. In which there is a form to upload a file on submit click.

YAHOO.util.Connect.setForm(document.getElementById('settings_Form'),true); 
YAHOO.util.Connect.initHeader('Content-type','text/javascript');
callbackFn =  {
 upload: function(html) {
  eval(html.responseText);
 }
};
YAHOO.util.Connect.asyncRequest('POST', 'pgRequests.php?t=settings', callbackFn);

pgRequests.php processes the file uploaded and returns some javascript codes like :

var servResponse = {"global_onOff":0,"off_msg":"OFF","id":0,"service":"Change Settings"};

But when "upload" is called, the 'html' variable contains the javascript code enclosed with <pre></pre> tag开发者_如何学Pythons. thats why eval() function is not working there.

I tried setting header in PHP file using :

header("Content-type: text/javascript; charset: UTF-8");
header("Cache-Control: must-revalidate");
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() - 1) . " GMT";
header($ExpStr);

but didnt work.

I searched on google, but many people are facing the same problem. Thats why i cant figure out where its getting wrong. What should i do to make it work? Is there any parallel way to implement the same flow?

Thanks in advance..!!


In your JSON encode -

replace < with &lt;

and also

replace & with &amp; 

:p


The YUI file upload occurs through an iframe. The responseText is the body of that iframe, hence where the <pre> tags come from.

       var responseNoPreTags = htmle.responseText.replace( /<\s*pre.*?>/g, '').replace ( /<\s*\/\s*pre\s*.*?>/g, '');

That should remove the <pre> tags aswell as any attributes. you should then be able to eval responseNoPreTags.

0

精彩评论

暂无评论...
验证码 换一张
取 消