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

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

  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.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

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

    The issue is a server security setting that does not allow AJAX requests from other domains. Since the script running is not locationed on the same host/domain as the query page, it will not work. Only way around that is if you control the server being queried. Then you can turn on cross origin access.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)