How to send authentication headers with jQuery Ajax -
i'm using domainapi site (which free far) handle domain availability checking. brief documentation here.
i'm new of may overlooking obvious. sec part of header username , password, encrypted base64 in format username:password. if access url directly, same username , password gives me access.
the code have far following, still fails:
$('#domain').keyup(function() { $("#loading").show(); $.ajax({ url: 'http://api.domainapi.com/v1/availability/example.com', type: 'get', datatype: 'json', success: function() { alert("success"); }, error: function() { alert('failed!'); }, beforesend: function setheader(xhr) {xhr.setrequestheader('authorization', 'basic zw1izxjza2vjadp6ewfrc21hdnnveny=');} }); });
it looks you're running cross-domain issues here.
ajax requests can performed cross-domain if server has cors-support (see http://en.wikipedia.org/wiki/cross-origin_resource_sharing more info) enabled, , quick check on api.domainapi.com
doesn't suggest does. if open browser's console, should error message saying much.
to solve this, you'll need implement sort of proxy on own server (which, because runs on same domain web page, should usable ajax 'target'), in turn forwards requests api.domainapi.com
.
jquery ajax
No comments:
Post a Comment