简体   繁体   English

无法从Web服务检索JSON数据

[英]Unable to retrieve JSON data from web service

I have an external web service that has JSON data. 我有一个具有JSON数据的外部Web服务。 I've validated that data is JSON through the JSON Validator website. 我已经通过JSON Validator网站验证了数据为JSON。 However, the below code success function does not run at all. 但是,下面的代码成功功能根本无法运行。 The web service requires that the email and password be passed through the url for the JSON data to be displayed. Web服务要求通过url传递电子邮件和密码,以便显示JSON数据。

The url to access the web service is as such: http://example.com/Email/Password 访问Web服务的网址是这样的: http : //example.com/Email/Password

How do I fix the below code to solve this issue. 如何修复以下代码来解决此问题。 Any help whatsoever will be appreciated. 任何帮助将不胜感激。

<script type="text/javascript">
    $(document).ready(function () {
        $("#frmLogin").submit(function (event) {
            event.preventDefault();
            var pm_url = 'http://example.com/';
            pm_url += $("#Email").val();
            pm_url += '/';
            pm_url += $("#Password").val();
            $.ajax({
                url: pm_url,
                type: 'GET',
                dataType: 'json',
                success: function(){
                    alert("Success");
                }
            });
        });
    });
</script>

Thanks. 谢谢。

So this seems to be a CORS issue, which has to do with security. 因此,这似乎是一个CORS问题,与安全性有关。 The browser will not allow requests to be dispatched that are external to your domain unless you explicitly allow it to. 除非您明确允许,否则浏览器将不允许调度您域外部的请求。 This is a good article that details several ways to allow CORS requests, if you google around you will find much more. 是一篇很好的文章,其中详细介绍了允许CORS请求的几种方法,如果您在Google周围搜索,将会发现更多信息。

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

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