Jump to content
Sign in to follow this  
hsidhu

REST Api Call

Recommended Posts

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.

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

Share this post


Link to post
Share on other sites
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.

Loading...
Sign in to follow this  

×
×
  • Create New...