我正在尝试使用ajax调用从服务器接收二维数组(键值对)。其中一个条目是一个图像(来自数据库的二进制流blob,它可以是png / jpeg等)。我当前的ajax调用能够接收数组并转换为JSON,如果没有图像条目。但是如果添加图像,我将收到一个空白数组。 我的代码看起来像这样 this.lastRefreshAt = new Date();
$.ajax({
type : 'GET',
data : {
view : JSON.stringify(this.view),
hours : this.hours,
start : this.startTime,
end : this.endTime
},
url : 'https://' + this.baseURL() + 'data/json/incidents',
success : function(data) {
appl.incidents.clear();
data = JSON.parse(data);
if(data.success && data.success == true && data.data) {
for(key in data.data) {
appl.incidents.set(parseInt(data.data[key].id), data.data[key]);
}
enter code here
我从php服务器收到的数据是
array(2) {
["success"]=>
bool(true)
["data"]=>
array(6) {
[0]=>
array(17) {
["id"]=>
int(5480)
["sys_datetime"]=>
string(22) "01/22/2018 06:37:36 PM"
["user_id"]=>
string(2) "41"
["date"]=>
string(10) "01/22/2018"
["time"]=>
string(8) "06:37 PM"
["title"]=>
string(2) "we"
["loc_type"]=>
string(1) "O"
["location"]=>
NULL
["priority"]=>
string(1) "3"
["description"]=>
string(2) "we"
["detail_date"]=>
string(10) "01/22/2018"
["detail_time"]=>
string(8) "06:37 PM"
["desk"]=>
int(106)
["contacts"]=>
array(0) {
}
["email_recipients"]=>
array(0) {
}
["details"]=>
array(0) {
}
["attachment"]=>
string(11041) "�PNG
IHDR�����tEXtSoftwareAdobe ImageReadyq�e<fiTXtXML:com.adobe.xmp<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27 "> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmpMM:OriginalDocumentID="xmp.did:97B8E55B506DE511BE28A2EE00A0604A" xmpMM:DocumentID="xmp.did:0C8029AA6D5A11E5BE80C2D4D01B8CF1" xmpMM:InstanceID="xmp.iid:0C8029A96D5A11E5BE80C2D4D01B8CF1" xmp:CreatorTool="Adobe Photoshop CS6 (Windows)"> <xmpMM:DerivedFrom stRef:instanceID="xmp.iid:98B8E55B506DE511BE28A2EE00A0604A" stRef:documentID="xmp.did:97B8E55B506DE511BE28A2EE00A0604A"/> </rdf:Description> </rdf:RDF> </x:xmpmeta> <?xpacket end="r"?>(��'QIDATx��} t\ՙ�_�T�*-�͒eaK��Ƌ�v�,2�IȘ�
�g�daΜ��i��ӧ�N��twN�b'3����I�@3i&6`����M�*[��}�}���>����^UI�������)�zU����r��_[,��<�����`�0L�I�`0i���`�0L�I�`0i���`�0L�I�`0i&
��`�0L�I�`0i�\���_�j��ڻe!�,�T��)�)�P|f%,�[!�(��9J������#M����!KQ�Ԥ�=�qߩ�v��(Ҙ��]��1+|(w��GY+4J�Q#d��o�����Fye���Ic��u���(y&�DžB���-�.a�180� blB�7��_��3)a��:q��3г�s����
ԣ|�a�g;\(�PP��(?z-
答案 0 :(得分:0)
我在php服务器上使用了base64_encode(),然后在客户端发送了关于base64编码的Javascript。