0

Trying to obtain the response from a GET services the ajax function always run into error section.

<!DOCTYPE html>

<!-- jquery -->
<link rel="stylesheet" href="jquery/jquery-ui.css">
<script src="jquery/jquery-1.11.1.min.js"></script>
<script src="jquery/jquery-ui.js"></script>

<!-- bootstrap -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
<script src="bootstrap/js/bootstrap.min.js"></script>

<script type="text/javascript">
$.ajax(
{
    url: "http://localhost:8080/POC-WebApplication/obtenerusuarios",
    type: "GET",
    dataType: "jsonp",
    success: function(data, textStatus, jqXHR) 
    {

        alert("success");
    },
    error: function(data, textStatus, jqXHR)
    {
        alert("FAIL!!!!\ndata: "+data+"\ntextStatus: "+textStatus+"\njqXHR: "+jqXHR);
    }
});
</script>

When the browser executes the code I got this results:

  • data: [object Object]
  • textStatus: parserror
  • jqXHR: Error: jQuery1111.....3111 was not called

I tried with dataType: "json" but I got this error in the chrome debug console:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

and the alerts print:

  • data: [object Object]
  • textStatus: error
  • jqXHR: Error:

****EDITED****

I solved it using this chrome app: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

I encourage everyone with the same problem as me to use it.

2
  • 1
    What URL are you using to access this document? Commented Dec 9, 2014 at 11:33
  • Try your AJAX Url as /POC-WebApplication/obtenerusuarios only. Commented Dec 9, 2014 at 12:05

1 Answer 1

0

As far I understand i think you have to add these lines to you .htaccess file

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
</IfModule>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.