Jump to content

Recommended Posts

Posted

Hello Everyone,

 

I am trying to make javascript ajax call to rest api of voida api e.g /rest/session but getting cors error.

I tried different solutions but didn't worked. I am using following code.

var vars = { "name": "auth", "value": "admin " + CryptoJS.MD5('password') };
$.ajax({
    type: "PUT",
    url: 'http://[pbx]/rest/system/session',
    headers:{
        "Access-Control-Allow-Origin": "*",
        'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With, Origin, Accept',
        'Access-Control-Allow-Methods': 'HEAD, GET, POST, PUT, DELETE, OPTIONS',
        },
    dataType: 'json',
    async: true,
    data: JSON.stringify(vars),
    success: function(data){
            console.log(data);
        },
    error: function(data){
        console.log(data);
        }
});

I am getting following errors

OPTIONS http://[pbx]/rest/system/session
send @ jquery.js:8630jQuery.extend.ajax
@ jquery.js:8166loadView
@ status.js:396(anonymous function)

XMLHttpRequest cannot load http://[pbx]/rest/system/session. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://[HOST]' is therefore not allowed access. The response had HTTP status code 403.

I also listed ip under access IP control

IF you guys can look into it will solve another problems for me.

Posted

Yeah, I am sending that query from different origin. Is there any work around that if i wanna to send this from different server.

 

The purpose of doing this is also related with setting up a websocket connection from different origin. Bcz its not possible to send custom header with javascript websocket client.

 

Authorization and websockets headers

Posted

Yeah, I tested that it works fine but the thing is than you have to go through few extra steps.

 

On the side not it only works with session cookie not with basic authorization.

 

Best Regards

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...