0
$.ajax({
    url: 'http://handshake.aid-dcc.asia/api/customer/get_user_list',
    type: 'POST',
    cache: true,
    dataType: 'json',
    beforeSend: function(xhr) {
        xhr.setRequestHeader("Authorization", 'Basic J25hbWFwcDpKbTZzdUdyayc=')
    },
    sucess: function(result) {
        alert('done');
    }
});

My problems are:

I load json file from url: http:handshake.aid-dcc.asia/api/customer/get_user_list. But The link will require username + pass when we open it. So, I used "Authorization" with EncodeBase64('username:password') in my code. I received some errors:

  1. OPTIONS http:handshake.aid-dcc.asia/api/customer/get_user_list 401 (Authorization Required)
  2. XMLHttpRequest cannot load http:handshake.aid-dcc.asia/api/customer/get_user_list. Origin http:localhost is not allowed by Access-Control-Allow-Origin.

What's wrong with my code?

4

1 回答 1

0

if you are using Chrome, you can start it with the parameter --disable-web-security

Or

use dataType: 'jsonp'

于 2013-03-14T07:19:00.340 回答