Formdata 和 XMLhttpRequest 在 IE 11 上不起作用
Formdata and XMLhttpRequest not Working on IE 11
我正在使用formdata
和XMLHttpRequest
来使用ajax提交我的表单。现在一切在其他浏览器上运行良好,除了 IE 11 .注意我正在使用此 ajax 请求上传文件。
我的代码如下
var form = document.getElementById('chatMessageForm');
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
// Add any event handlers here...
xhr.open('POST', form.getAttribute('action'), true);
xhr.responseType = "json";
xhr.send(formData);
xhr.onload = function (e) {
var new_message_response = xhr.response; // not responseText
console.log(new_message_response);
if (new_message_response.conversationStatus) {
alert('This Conversation is disabled by Other User');
jQuery('.conversationadd .messagebox #msgbox').attr('disabled',true);
} else {
var downloadLink = '';
if (new_message_response.attachment != '' && new_message_response.attachment != null) {
downloadLink = '<a href=" ' + new_message_response.attachment_file_path + '" download="' + new_message_response.attachment + '" class="attachment">Download Attachment</a>';
}
jQuery('.chatmessageinner').append('<div class="singlemsg right" id=" ' + new_message_response.id + ' ">'
+ '<p> ' + msg + ' </p>'
+ '<div class="messagefooter">'
+ '<span class="time">' + new_message_response.time + '</span>'
+ downloadLink
+ '</div>'
+ '</div>');
var objDiv = document.getElementsByClassName("chatmessageinner")["0"];
objDiv.scrollTop = objDiv.scrollHeight;
}
}
我使用了jQuery.ajax而不是XMLhttpRequest,现在一切都像丝绸一样流畅:)现在我的代码如下所示:
var form = document.getElementById('chatMessageForm');
var formData = new FormData(form);
jQuery.ajax({
url: form.getAttribute('action'),
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function (data) {
var new_message_response = data;
if (new_message_response.conversationStatus)
{
alert('This Conversation is disabled by Other User');
jQuery('.conversationadd .messagebox #msgbox').attr('disabled', true);
}
else
{
var downloadLink = '';
if (new_message_response.attachment != '' && new_message_response.attachment != null)
{
downloadLink = '<a href=" ' + new_message_response.attachment_file_path + '" download="' + new_message_response.attachment + '" class="attachment">Download Attachment</a>';
}
jQuery('.chatmessageinner').append('<div class="singlemsg right" id=" ' + new_message_response.id + ' ">'
+ '<p> ' + msg + ' </p>'
+ '<div class="messagefooter">'
+ '<span class="time">' + new_message_response.time + '</span>'
+ downloadLink
+ '</div>'
+ '</div>');
var objDiv = document.getElementsByClassName("chatmessageinner")["0"];
objDiv.scrollTop = objDiv.scrollHeight;
}
},
error: function (data) {
alert("error");
}
});
相关文章:
- window.opener.document在ie中不起作用
- 为什么Telerik cdn在IE中不起作用
- JQuery脚本在IE中不起作用
- 默认光标在IE和Mozilla中不起作用
- Asp自定义验证器在IE-11中不起作用
- knockoutjsforeach在IE 9中不起作用
- 谷歌分析在IE中不起作用
- javascript中的SVG转换在IE 11中不起作用
- 用于播放背景音乐的嵌入式flash播放器在IE浏览器中不起作用
- 在IE中切换javascript不起作用的复选框
- JQuery日期选择器在IE 7上不起作用
- HTML表单在IE中不起作用
- Javascript style.background在IE中不起作用
- 对<asp:IE 10的TextBox;不起作用
- Javascript/AAJAX在Opera中不起作用,在FF/IE/Chrome中完美工作
- SPA异步调用在IE 11中不起作用
- 脚本在IE 9中不起作用
- ng-单击在IE中不起作用的选项选择Angularjs
- html2canvas 代码不起作用 IE 11
- 隐藏选项不起作用IE