简体   繁体   English

PHP的Angular和JSON保护

[英]Angular and JSON protection with PHP

In the $http documentation, I'm told to prefix my response with )]}',\\n how can I do that in PHP? 在$ http文档中,有人告诉我在响应前面加上)]}',\\n如何在PHP中做到这一点? And how do I access the returned data object once done? 以及完成后如何访问返回的数据对象?

        error(function(data, status, headers, config) {  
            $scope.error = data.error;
        });


echo json_encode(array('error' => $error)); //You messed up Leroy!

The following should work. 以下应该工作。

echo ")]}',\n" . json_encode(array('error' => $error));

About angular: I think the function you have is correct. 关于angular:我认为您拥有的功能是正确的。 But if it's not working, it's useful to console.log(data) , and find, which structure it has. 但是,如果它不起作用,则console.log(data)并查找其具有的结构很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM