1

I want to send data with ajax jquery to a web service in laravel 5.3. my ajax code is(URL in this question is an example):

 $.ajax({
        type: "POST",
        url: "http://199.166.212.50:8080/.../add",
        contentType:'application/json',
        data: {
            "requester":
            {
                "userName": "jac",
                "password": "111"
            },
            "request":
            {
                "userName":userName,
                "password":password,
                "firstName": firstName,
                "lastName": lastName,
                "homeLocationLatLong":
                {
                    "latitude": homeLocationLatLong_latitude,
                    "longitude": homeLocationLatLong_longitude
                },
                "homeLocationText": homeLocationText,
                "homePhoneNumber": homePhoneNumber,
                "cellPhoneNumber": cellPhoneNumber

            }

        },
        dataType: "json",
        success: function (result) {
           console.log(result);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }
    })

but when i send data, i see this error:

XMLHttpRequest cannot load http://199.166.212.50:8080/.../add. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.

what can i must do?

narges
  • 681
  • 2
  • 7
  • 26
  • 1
    Possible duplicate of [jQuery AJAX cross domain](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) – Mike Scotty Dec 22 '16 at 09:25

2 Answers2

1

I had same problem. i use this link and add Allow-Control-Allow-Origin: * to the chrome browser.

z.gomar
  • 372
  • 2
  • 11
0

Try Like this it will work for you.

 <script>
  $("#login_info").click(function(){
    var name = $('#username').val();
    var pass = $('#password').val();
    var token_key =  $('input[name=_token]').val();
      $.ajax({
       type: "POST",
       url: '{{url("admin_panel/login/auth")}}',
       data: {
        '_token': token_key,
        'username': name,
        'password': pass
      },
       success: function(data)
       {
        alert('in_sucess');
       }
    })
});   

Priyank lohan
  • 483
  • 1
  • 6
  • 17