javascript - Adding basic http authorization in a ajax json script -


not sure how add authentication in ajax call json information. trying follow examples given http://domainapi.com/documentation/how-to-use-domainapi/servuces-provided/domain-availability-api.html check availability of domain name, keeps doing http form pop asking username , password.

i thought had right in code:

function domainavailabilitycheck(domain) {     $.ajax({         type: 'get',         url: 'http://api.domainapi.com/v1/availability/'+domain+'.com',         beforesend: setheader,         success: function(spitback) {             console.log(spitback.content.domainlist.status);         },         datatype:'jsonp'     }); }  var setheader = function(xhr) {     xhr.setrequestheader('authorization', 'basic ywtpcmf0zxn0omr0d3n0zxn0'); } 

not sure doing wrong.

your beforesend isn't allowing jquery pass in xhr object header modifications. line should be

beforesend: function(xhr) { xhr.setrequest(......); } // all-in-one, no function needed 

or

beforesend: function(xhr) { setheader(xhr); } // call separate function 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -