Created
December 26, 2016 15:47
-
-
Save gelanivishal/f8a415d72a6a8afcc66b891205c9a5cc to your computer and use it in GitHub Desktop.
Converting curl cmd to jQuery $.ajax() From http://stackoverflow.com/questions/20155531/converting-curl-cmd-to-jquery-ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
url: "http://www.example.com/api", | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password")); | |
}, | |
type: 'POST', | |
dataType: 'json', | |
contentType: 'application/json', | |
processData: false, | |
data: '{"foo":"bar"}', | |
success: function (data) { | |
alert(JSON.stringify(data)); | |
}, | |
error: function(){ | |
alert("Cannot get data"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment