开发者

XML cannot be the whole program

开发者 https://www.devze.com 2023-01-23 22:47 出处:网络
XML cannot be the whole program - anyone else seen this firebug error? happening when receiving remote data (json, as it were) via ajax.

XML cannot be the whole program - anyone else seen this firebug error? happening when receiving remote data (json, as it were) via ajax.

If data type changed json to html, working fine.

This is my actual code in php:

I reloaded the page, once session has been expired.

if($action->getRequest()->isXmlHttpRequest())
{           
  $action->getResponse()->setContent("<script>window.location.reload();</script>");      
  $action->getResponse()->send();      
}

firebug displ开发者_StackOverfloways the following error:

XML cannot be the whole program [Break on this error] window.location.reload();


Are you passing it the correct data format from the Ajax call? The error says it's something to do with XML, but you said you had it set to JSON, not XML.


You're sending the string "<script>window.location.reload();</script>" which does not contain JSON/JS but HTML. So the client tries to interpret the string as JSON/JS but notices that the whole script is just a single XML literal.


You cannot use the tags while loading in this way. Try to load the Javascript statements without using the tags in the loaded file. e.g:

This code generates the same error, if I load it dynamically.

<?php
    echo "<script type='text/javascript'>alert('Hi');</script>";
?>

This code doesn't generate any error and instead works like a charm:

<?php
    echo "alert('Hi');";
?>

This should help you out.

0

精彩评论

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

关注公众号