简体   繁体   English

Json在javascript或jquery中解析

[英]Json parsing in javascript or jquery

<!doctype html>
<html>
<head>
    <title>Parsing</title>
    <script type="text/javascript" src="jquery-2.1.0.min.js"></script>

</head>
    <script>
        alert("ciao");
        $.getJSON('', { get_param: 'value' }, function(data) { 

        });
    </script>

    <body >
        <p>ciao<p>
    </body>

</html>

With this code I want to parse this JSON: 使用此代码,我想解析此JSON:

asd'cp'pd'pcd'sp'sdp'dc asd'cp'pd'pcd'sp'sdp'dc

The browser console give me this error (I don't understand what it means): 浏览器控制台给我这个错误(我不明白这意味着什么):

XMLHttpRequest cannot load http://sath3g.altervista.org/index.php?get_param=value. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 

What is wrong? 怎么了?

I think your are trying to do a cross domain ajax request.Browser will block the request because of Access-Control-Allow-Origin . 我认为您正在尝试执行跨域ajax请求。由于Access-Control-Allow-Origin将阻止请求。

If you need to access the data from another domain i'll suggest you to use jsonp . 如果您需要访问其他域中的数据,我建议您使用jsonp But for that, the required server should bind the return data with a client side function. 但为此,所需的服务器应该将返回数据与客户端功能绑定。

Refer this . 请参阅

Also you can try enabling cors in the ajax request. 您也可以尝试在ajax请求中启用cors

You can use crossDomain: true in jQuery ajax. 您可以在jQuery ajax中使用crossDomain: true
Check this link for details 请查看此链接了解详情

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

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