如何将jquery ajax响应转换为base 64 [英] how to convert jquery ajax response to base 64
本文介绍了如何将jquery ajax响应转换为base 64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script>
$( document )。ready( function (){
$(' #btnLogin')。click(功能(){
$ .ajax({
url:' testurl',
类型:' 获取',
beforeSend: function (xhr){
xhr.setRequestHeader( 授权, 基本 + btoa( username + : + 密码));
},
成功:功能(响应){
console .log(响应)
$(' #imga')。html (' < img src =data:image / gif; base64,' + response + ' />');
},
错误:功能(错误){
alert( 错误)
console .log(错误)
}
});
});
});
< / script>
< input 类型 = 按钮 id = btnLogin value = 登录 / >
< div id = imga > < / div >
$ b $b 〜?em0Ra ??升{wV7ہ} H 19 pIahqçؽ?X XVcx R ?? + DP ҙcZE?? | * ??? U6Dߛ)$〜? jSD ? *?xe M A #
1)我检索这类数据我能知道这是什么吗?
2)如何使用Jquery将此数据转换为base64?
解决方案
( document )。ready( function (){
(' #btnLogin')。点击( function (){
.ajax({
url :' testurl',
类型:' 获取',
beforeSend: function (xhr){
xhr.setRequestHeader( 授权, Basic + btoa( username + : + 密码跨度>));
},
成功:功能(响应){
console 跨度> .log中(响应)
<script>
$(document).ready(function () {
$('#btnLogin').click(function () {
$.ajax({
url: 'testurl',
type: 'Get',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username" + ":" + "Password"));
},
success: function (response) {
console.log(response)
$('#imga').html('<img src="data:image/gif;base64,' + response + '" />');
},
error: function (error) {
alert("error")
console.log(error)
}
});
});
});
</script>
<input type="button" id="btnLogin" value="Login" />
<div id="imga"></div>
��~e��m0R�a���l�����{ ��wV�7ہ�}��h��p�I������ahq ��cؽ�X �XV�c�x"r���+�d��p"�ҙ���cZ�E|*��U6�D��ߛ�)�$~�jSD��*xe���M�A�#
1) I am retrieve this type of data can i know what is this ?
2) how to convert this data to base64 using Jquery ?
解决方案
(document).ready(function () {
('#btnLogin').click(function () {
.ajax({ url: 'testurl', type: 'Get', beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", "Basic " + btoa("username" + ":" + "Password")); }, success: function (response) { console.log(response)
这篇关于如何将jquery ajax响应转换为base 64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文