CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Dec 2016
    Posts
    6

    How to avoid the error ' No 'Access-Control-Allow-Origin' header' on an Ajax call

    My code below is :

    Code:
    function getTicket() {
    	
    	try {
    	
    	alert("Get Ticket")
    	
    	var tableauInfo = {
                username: "xxxxxxxx",
                site_root:"POC1",
               client_ip:"xx.xxx.xxx.xx"
            }
    
           //$('#getTicket').html('sending..');
    	var dashboardResourceURL = "https://analytics.xxxxxxx/trusted/##TOKEN##/t/POC1/views/ExampleVis/Dashboard1?:iid=1"
    	var resourceURL = "https://analytics.xxxxxxxxxxx/trusted"
    	 $.ajax({
    		 	method: 'POST',   
    		 	url: resourceURL,
                data: JSON.stringify(tableauInfo),
                dataType: 'html',
                contentType:'application/x-www-form-urlencoded; charset=UTF-8',
                crossDomain: true,
    	 })
                .success(function (result) {
                	alert(Json.stringify(data));
                	dashboardResourceURL.replace("##TOKEN##",result);
                	alert(dashboardResourceURL);
                	$('#tokenurl').show();
                	$('#tokenurl').src= dashboardResourceURL;
                    $('#getTicket').html(data.msg);
                })
                .fail(function(data){
                	console.log('failed!! ', data);
                	
                    $('#getTicket').html("Error retrieving ticket from Tableau server");
                	
                });
    	}
    	
                catch(err){
                  console.log('an unforseen error occurred; it is ', err);
                }
               
    
           }
    I'm performing a client side request to hit the server and get a token and get the response object of token and repost the dynamic token to server to get the image on the browser

    I'm getting an error:
    No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

    Please suggest how to get rid of this error.
    Thanks in advance.
    Last edited by 2kaud; December 19th, 2016 at 12:41 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured