te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>jquery - Javascript : Uncaught InvalidStateError: Failed to read the 'selectionDirection' - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Javascript : Uncaught InvalidStateError: Failed to read the 'selectionDirection' - Stack Overflow

programmeradmin3浏览0评论

I've got this error message :

Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('hidden') does not support selection.

When I check the console, it says error in this code:

function simpan() {
    $.ajax({
        url: 'app/tblhasilsurvey/simpan',
        type: 'post',
        async: false,
        data: {
            cmd: window.cmd,
            id: window.id_hasilsurvey,
            id_daftar: window.id_daftar,
            id_jadwal: window.id_jadwal,
            //tblhasilsurvey_nobasurvey : $("#nomor_ba_survey").val(),
            nomor_izin : $("#nomor_izin").val(),
            tgl_izin : $("#tgl_izin").val(),
            pemilik_izin : $("#pemilik_izin").val(),
            lokasi : $("#lokasi").val(),
            kodekel : $("#kelurahan").val(),
            kodekec : $("#kecamatan").val(),
            tblhasilsurvey_tglbasurvey : $("#tgl_ba_survey").val(),
            tbldaftarrencanasurvey_koordinat : $("#lattitude_").val()+';'+$("#longitude_").val(), // (lattitude;longitude)
            tblhasilsurvey_fungsibangunan : $("#fungsi_bangunan").val(),
            tblhasilsurvey_uraianpermasalahan : $("#uraian_permasalahan").val(),
            tblizin_id : $("#tblizin_id").val()
        },
        success: function (data) {
            if(data=='success') {
                notifikasi('Sukses','Data Berhasil Disimpan', 'success');
                //window.location.reload();
            } else {
                notifikasi('Gagal','Data Gagal Disimpan', 'fail');
            }
        }
    });
    if( $("#lattitude_").val() !='' ) window.pos_lat = $("#lattitude_").val(); // jika koordinat terisi maka update posisi lattitude
    if( $("#longitude_").val() !='' ) window.pos_long = $("#longitude_").val(); // jika koordinat terisi maka update posisi longitude

    $("#peta-lokasi").slideDown(1000);
    initialize();
    $("html, body").animate({ scrollTop: $(document).height() }, 2500);
    return false;

    function refresh () {
        window.location.reload();
    }
}

Can someone explain me what happen here?

I've got this error message :

Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('hidden') does not support selection.

When I check the console, it says error in this code:

function simpan() {
    $.ajax({
        url: 'app/tblhasilsurvey/simpan',
        type: 'post',
        async: false,
        data: {
            cmd: window.cmd,
            id: window.id_hasilsurvey,
            id_daftar: window.id_daftar,
            id_jadwal: window.id_jadwal,
            //tblhasilsurvey_nobasurvey : $("#nomor_ba_survey").val(),
            nomor_izin : $("#nomor_izin").val(),
            tgl_izin : $("#tgl_izin").val(),
            pemilik_izin : $("#pemilik_izin").val(),
            lokasi : $("#lokasi").val(),
            kodekel : $("#kelurahan").val(),
            kodekec : $("#kecamatan").val(),
            tblhasilsurvey_tglbasurvey : $("#tgl_ba_survey").val(),
            tbldaftarrencanasurvey_koordinat : $("#lattitude_").val()+';'+$("#longitude_").val(), // (lattitude;longitude)
            tblhasilsurvey_fungsibangunan : $("#fungsi_bangunan").val(),
            tblhasilsurvey_uraianpermasalahan : $("#uraian_permasalahan").val(),
            tblizin_id : $("#tblizin_id").val()
        },
        success: function (data) {
            if(data=='success') {
                notifikasi('Sukses','Data Berhasil Disimpan', 'success');
                //window.location.reload();
            } else {
                notifikasi('Gagal','Data Gagal Disimpan', 'fail');
            }
        }
    });
    if( $("#lattitude_").val() !='' ) window.pos_lat = $("#lattitude_").val(); // jika koordinat terisi maka update posisi lattitude
    if( $("#longitude_").val() !='' ) window.pos_long = $("#longitude_").val(); // jika koordinat terisi maka update posisi longitude

    $("#peta-lokasi").slideDown(1000);
    initialize();
    $("html, body").animate({ scrollTop: $(document).height() }, 2500);
    return false;

    function refresh () {
        window.location.reload();
    }
}

Can someone explain me what happen here?

Share Improve this question edited Dec 26, 2014 at 16:17 Alexander O'Mara 60.6k19 gold badges172 silver badges181 bronze badges asked Dec 26, 2014 at 16:08 ChristChrist 811 gold badge1 silver badge4 bronze badges 1
  • Which specific line has the error? Is there a stack trace? The error seems self explanatory; something (maybe not in this code, but in something it calls like notifikasi or initialize) is probably trying to read selectionDirection on a hidden element. – Jacob Commented Dec 26, 2014 at 18:38
Add a ment  | 

1 Answer 1

Reset to default 14

Somewhere in your HTML you have an <input type='hidden' /> which you are trying to add to your data obj, but you are probably adding the jQuery object and this message is likely getting thrown when the jQuery object is being stringified somewhere. Given most of your data object is built by explicitly calling .val() I'd guess the problem lies with one of these:

        cmd: window.cmd,
        id: window.id_hasilsurvey,
        id_daftar: window.id_daftar,
        id_jadwal: window.id_jadwal,

try menting those out and see if your error goes away. If it does, then the problem can probably be solved by adding .val() to the end of the problematic line.


EDIT AND EXTENSION

(Apr 9, 2015) This answer has had 3 upvotes since I wrote it, all spread out in time, so I guess other people are hitting this error and finding this answer, so here is a more general explanation to help people out.

This error is thrown if you add the jQuery object representing a hidden input to a JS object, then try to serialise that JS object to JSON.

Demo reproducing the error in its simplest form:

http://jsfiddle/ptugva6t/2/

Using this HTML:

<input type="hidden" id="test1" value="test1_val" />

Then #test1 will trigger the error if we use this JS:

$(document).ready(function() {
    var data = {
        test1: $("#test1")
    }
    JSON.stringify(data)
});

whereas this will be OK:

$(document).ready(function() {
    var data = {
        test1: $("#test1").val()
    }
    JSON.stringify(data)
});

Whereas if you use a text input you won't hit this error, but you will likely hit other serialisation errors due to the plexity of the object you are trying to serialise!


UPDATE

(7 September 2016) It looks like this was only ever a Chrome bug and it has been fixed in a recent Chrome update. There is now no error at all in Chrome 52 and you can JSON.stringify a jquery object with no problem.

Firefox is also OK. Safari 9.1.1 still throws an error, though - a TypeError on JSON.stringify that can be fixed by adding the .val()

So there's a mini-project arising, to find the Chrome bug report and its fix, and report it to Safari.

发布评论

评论列表(0)

  1. 暂无评论