我在本地服务器上安装了ApacheOpenmeetings。如何从其他应用程序访问rest api?

时间:2017-09-19 06:09:31

标签: php ajax openmeetings

从localhost请求时出现以下错误: -

XMLHttpRequest无法加载http://192.168.1.3:5080/openmeetings/services/user/login?user=user&pass=pass。 No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' http://localhost'因此不允许访问。

代码写为

<script>
        $(document).ready(function(){
            $("#meet").click(function(){
                $.ajax({
                    method: "GET",
                    url: "'.$server.'services/user/login",
                    data: {user: "user", pass: "pass"},
                    dataType: "json",
                    success : function(data){
                    if(data["serviceResult"]["code"]==1){
                        var code = data["serviceResult"]["message"];
                        $.ajax({
                        method: "POST",
                        url: "'.$server.'services/user/hash?sid=" + code ,
                        data: {user: JSON.stringify({
                            firstname: "Edubeans",
                            lastname: "Student",
                            externalId: "uid1",
                            externalType: "myCMS",
                            login: "pivotal"
                        }),
                        options: JSON.stringify({
                            roomId: 7,
                            moderator: true,
                            showAudioVideoTest: true
                        })
                         },
                         dataType: "json",
                         success : function(data1){
                         $("#link").html(\'<a href="'.$server.'hash?secure=\'+data1["serviceResult"]["message"]+\'&language=1" target="_blank">Please click here to Enter the room.</a>\');     
                    }


                })                                      
                }
            }
        });                                     
    });                 
});
</script>

1 个答案:

答案 0 :(得分:0)

您的来源是localhost,但您正尝试访问位于192.168.1.3的其他来源。

192.168.1.3更改为localhost

而不是从http://localhost执行代码,而不是从http://192.168.1.3

执行代码