1

Maybe I'm the Nth user that ask this question, but I can't figure it out.

The data string of the ajax call seems to be empty or what? Either I don't get any feedback on the succes or error function.

$.ajax({
  type:'POST',
  url:'http://www.example.com/test.php',
  data:'lid=test',
  succes: function(data){
    console.log(data);
  },
  error:function(data){
    console.log(data);
  }
});

I hope someone can help me out with it?

Kind regards,

Frank

Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
Frank
  • 499
  • 2
  • 10
  • 22

6 Answers6

5

There's no succes function. You probably mean success.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
3

This is because of the Same origin policy. you cannot use ajax to call external sites. if you really want to use, you have to use JSONP. Or you can use serverside proxy for this. means, call external site in the server side and do ajax call to the that webservice.

for more information please refer this link and this answer https://stackoverflow.com/a/8698786/880434

Community
  • 1
  • 1
Chamika Sandamal
  • 23,565
  • 5
  • 63
  • 86
2

Try this

 $.ajax({
        type:'POST',
        url:'http://www.example.com/test.php',
        crossDomain: true,
        data:'lid=test',
        success: function(data){
            console.log(data);
        },
        error:function(data){
            console.log(data);
        }
    });
Sudz
  • 4,268
  • 2
  • 17
  • 26
1

AJAX requests are generally limited to same domain. Here is some information I found on another Stack Overflow Answer, Using Access-Control-Allow-Origin header

Alternatively, if your response is of the right format, you could try a JSONP request

Community
  • 1
  • 1
Turnerj
  • 4,258
  • 5
  • 35
  • 52
1

You're being blocked by the browser "Same origin policy". That is, you cannot do ajax requests to other than the same domain that the script was loaded from. There are, however, some workarounds:

  1. Use JSONP. This is probably the most cross browser compatible solution
  2. Configure your application to support CORS. This works in most modern browsers, but not in some older.
  3. Create a proxy service on your own server. That is, mount an endpoint, e.g. /externalService that proxies the request on the server side to the remote endpoint. It also will work in all browsers, but will involve more work on the server side.
NilsH
  • 13,705
  • 4
  • 41
  • 59
0

The server www.example.com should have the cross-domain.xml which will contain the domain names allowed to request and get response. So add your domain from which the request is coming or just add the doamin name as '*' to accept all doamins

user2120928
  • 88
  • 1
  • 8