使用$('.ajax_form').ajaxForm()的奇怪行为; [英] strange behavior using $('.ajax_form').ajaxForm();

查看:76
本文介绍了使用$('.ajax_form').ajaxForm()的奇怪行为;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次将jquery ajaxForm应用于类似以下的类

It is my first time to apply jquery ajaxForm on a class like the following

<form class="ajax_form"...><input type="text" name="q" /><input type="submit" /></form>
<form class="ajax_form"...><input type="text" name="q" /><input type="submit" /></form>

<script>
$('.ajax_form').ajaxForm({
  dataType: 'json',
  error: ajaxErrorHandler,
  success: function(response) { // do some ui update .. }
});
</script>

现在,在Ajax调用完成之后,我总是进入错误部分,尽管Firebug并未报告任何错误响应,但不确定我做错了什么.

Now after Ajax call is completed I always get into error section although firebug didn't report any errors response not sure what I did wrong.

推荐答案

在这种情况下这可能合适,但我会提供它,因为当我寻找答案时,它对我很有用类似的问题.如果您要通过Firefox在文件上传中提交多部分/表单数据"表单,jquery.form将使用iframe提交表单.如果返回数据的Content-Type为text/plain,则iframe会将结果文本包装在< pre>中.标记,即使Firebug正确显示了响应甚至json,也会使jquery json解析器产生错误,并给您一个解析器错误.

This may or not be appropriate in this case, but I'll provide it because it would have been useful to me when I was searching for the answer to a similar problem. If you are submitting a "multipart/form-data" form with file upload in Firefox, jquery.form will use an iframe to submit the form. If the Content-Type of your return data is text/plain, the iframe will wrap the resulting text in <pre> tags which will hork the jquery json parser and give you a parser error even though Firebug shows the response and even the json correctly.

在我弄清楚之前,这让我头疼不已(在此线程的帮助下: http://www.extjs. com/forum/archive/index.php/t-17248.html ).

This caused me no end of headaches before I figured it out (with help from this thread: http://www.extjs.com/forum/archive/index.php/t-17248.html).

在我的案例中,答案是确保响应的Content-Type为"text/html"(至少对我来说是违反直觉的).

The answer in my case was to make sure the response Content-Type was "text/html" (which was counter-intuitive, at least for me).

这篇关于使用$('.ajax_form').ajaxForm()的奇怪行为;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆