jQuery的形式插件在IE9无JSON响应 [英] No JSON response in jQuery form plugin in IE9

查看:99
本文介绍了jQuery的形式插件在IE9无JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 http://www.malsup.com/jquery/form/#ajaxForm 我的形式。 我建立了一个表格阿贾克斯上传图片到服务器。一切工作正常,而不IE9 :)。 我无法从服务器的JSON响应,但在其他浏览器中正常工作。 我试图把一些警报()成功函数中,但它看起来成功的功能是不是事件时加载。

I use http://www.malsup.com/jquery/form/#ajaxForm to my forms. I set up an form to upload images to the server by Ajax. Everything works fine without IE9 :). I can't get the JSON response from the server, although on the other browsers it works correctly. I tried to put some alert() within the success function, but it looks the success function isn't event loaded.

我的JS code:

$(function() {

    $('#upload-image').ajaxForm({
        dataType:  'json',
        success: processJson
    });

    function processJson(data) {
        var i = 0;
        $.each(data, function(key, val) {
            $('<li id="image_' + key + '"><input type="checkbox" name="delete_image[' + key + ']" /><img src="' + val + '" alt=""/></li>').hide().appendTo('#images').delay(i).fadeIn('slow');
            i += 1000;
        });
    }

});

和code产生在PHP中的JSON响应:

and code to generate JSON response in PHP:

    $output = array();

    foreach ($files['Filedata'] as $file)
    {
        $file_arr = $this->_save_image($file);

        $image = ORM::factory('image');

        $image->filename = $file_arr['filename'];
        $image->gallery_id = $gallery_id;
        $image->save();

        $output[$image->id] = Route::get('uploads')->uri(array('dir' => 'images/120x120', 'file' => $image->filename));

    }
    $this->request->headers('Content-type','application/json; charset='.Kohana::$charset);
    $this->response->body(json_encode($output));

我发现有关类似问题(删除从响应html标签)有些职位,但它并不能帮助我。 什么是错的?

I found some posts about similar issues (to remove html tags from the response), but it doesn't help me. What is wrong?

编辑: 在IE浏览器调试模式跟我说,访问被拒绝上线form.submit();在jQuery的形式插件库。 这似乎是某种形式的安全否认与本地主机上运行的JavaScript相关的。

The IE debug mode told me that the access has been denied on the line with "form.submit();" within the jQuery form plugin library. It seems to be some kind of security denial related with running javascript on localhost.

推荐答案

这可能是造成IE9不承认字符集的错误。我不得不面对类似的问题。

This can be an error caused by IE9 by not recognising the Character Set. I had to face a similar problem.

我这,这应该有助于

$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});

这篇关于jQuery的形式插件在IE9无JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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