ajax停止工作,Internet Explorer中的Ajax和JSON响应错误(适用于所有其他浏览器)

由于某些原因,IE要求我们下载文件而不是将其作为ajax运行。这适用于除IE以外的所有浏览器。我试图搞乱它与标题返回没有运气。Internet Explorer中的Ajax和JSON响应错误(适用于所有其他浏览器)

该函数获取表单数据然后发布它的响应是一个可以是任何数量的项目更新在页面上的数组。

它并不假设它是假设它只是一个json响应。

PHP

header('Content-type: application/json');

$error = "The Email and Password you entered could not be resolved.";

$elements[0]['target'] = '.error_report';

$elements[0]['action'] = 'inside';

$elements[0]['data'] = '

'.$error.'

';

$this->output->set_output(

json_encode(array("elements" => $elements))

);

的Javascript

$(document).ready(function() {

jQuery.ajaxSetup({

cache: false,

dataType: 'json',

error: function() {

alert("Request was not successful. Please try again shortly.");

}

});

$(document).ajaxSuccess(function (e, xhr, settings) {

var response = xhr.responseText;

if (settings.dataType != 'json') {

return;

};

try {

response = jQuery.parseJSON(response);

} catch (e) {

alert(e);

return;

}

if (response.elements instanceof Array) {

var reqs = ['target', 'action'];

var valid = true;

for (var i=0;i

var cur = response.elements[i];

var sel;

for (var j=0;j

if (typeof cur[reqs[j]] !== "string") {

valid = false;

break;

};

};

if (!valid) {

continue;

};

sel = $(cur.target);

switch (cur.action) {

case "inside":

sel.html(cur.data);

break;

case "instead":

sel.replaceWith(cur.data);

break;

case "remove":

sel.remove();

break;

case "refreshPage":

window.location.reload();

default:

if (typeof sel[cur.action] === "function") {

sel[cur.action](cur.data);

}; // else continue

break;

};

};

};

// Dispatch the AJAX request, and save it to the data object so that

// is can be referenced and cancelled if need be.

self.data('ajaxify.xhr', jQuery.ajax({

url: this.action,

type: 'post',

dataType: options.dataType,

data: (beforeSubmitIsJquery ? beforeSubmitResult.serialize()

: self.serialize()),

success: function (/**/) {

cleanup();

options.onSuccess.apply(that, arguments);

},

error: function (/**/) {

cleanup();

options.onError.apply(that, arguments);

},

complete: function (/**/) {

options.onComplete.apply(that, arguments);

}

}));

2010-08-31

Walker

+0

尝试在'.ajax'请求中将'contentType'设置为'application/json'。 –

2010-08-31 21:34:29

+0

我想为此提供200分的赏金,但它不会让我这样做分两天:( –

2010-08-31 21:34:45

+0

已经尝试调整内容类型:如果我们从标题切换到纯文本或JSON它加载一个新的页面与它的JSON响应 - 而不是像contentType标题(这两者都是错误的)下载响应。 –

2010-08-31 21:36:21

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值