Chrome javascript/jquery重定向到索引

Chrome javascript/jquery重定向到索引,javascript,jquery,google-chrome,Javascript,Jquery,Google Chrome,编辑:我在meanshile搜索了一下,发现chrome不允许本地文件,这可能是原因吗 我已经创建了我的第一个网站,主要包括php和jQuery以及一些JavaScript,在Firefox上一切都很好,我的问题是chrome,每当我在特定选项卡中提交表单时,它会运行所有内容,但会重定向到索引,而不是打印结果 这里是我的功能 function cshoptab(tab) { // for register.php var tab = tab; switch (tab) {

编辑:我在meanshile搜索了一下,发现chrome不允许本地文件,这可能是原因吗

我已经创建了我的第一个网站,主要包括php和jQuery以及一些JavaScript,在Firefox上一切都很好,我的问题是chrome,每当我在特定选项卡中提交表单时,它会运行所有内容,但会重定向到索引,而不是打印结果

这里是我的功能

function cshoptab(tab) {   // for register.php
    var tab = tab;
    switch (tab) {
        case 'weapons':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/weapons.php');
            break;
        case 'helms':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/helms.php');
            break;
        case 'suits':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/suits.php');
            break;
        case 'gloves':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/gloves.php');
            break;
        case 'boots':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/boots.php');
            break;
        case 'style':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/style.php');
            break;
        case 'costumes':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/costumes.php');
            break;
        case 'pets':
            $("#cshopwrap").html('Loading').show();
            $("#cshopwrap").load('php/cshop/pets.php');
            break;
    }
}
function cshopsenditem(idxvalue, opt, duration) {
    $("#content").html('Loading purchase').show();
    var idxvalue = idxvalue.split('x');
    var idx = idxvalue[0];
    var price = idxvalue[1];
    var url = "php/cshop.php";
    $.post(url, {idx: idx, price: price, duration: duration, opt: opt}, function(data) {
        $("#content").html(data).show();
    });
}
PHP:


表格:

<form name=form method='post'  onsubmit='cshopsenditem(document.getElementById("idx").value, 
                                                    null, 
                                                    document.getElementById("duration").value)'>
            <table>
                    <tr>
                        <td rowspan=9><img src=cimg/style.png></td>
                        <td>Item: </td>
                        <td>
                            <select name=idx id='idx' onchange='updateprice(document.getElementById("idx").value)'>
                                <option value=901x100>Change Kit - Hair Style (Novice)</option>
                                <option value=904x100>Change Kit - Hair Color (Normal)</option>
                                <option value=906x100>Change Kit - Face (Novice)</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Restriction: </td>
                        <td>Account Binded</td>
                    </tr>
                    <tr>
                        <td>Duration: </td>
                        <td>Permanent</td>
                    </tr>

                    <tr>
                        <td>Price: </td>
                        <td><div id='price'>100</div></td>
                    </tr>
                    <tr>
                        <td colspan=2 class='cshopbuybutton'>
                            <input name=duration id='duration' type=hidden value=31>
                            <input name=buybutton type=submit class='button' value='BUY NOW'>
                        </td>
                    </td>
                </table>
        </form>

项目:
更改套件-发型(新手)
更换套件-头发颜色(正常)
更换套件-面部(新手)
限制:
帐户绑定
持续时间:
永久的
价格:
100

可能是因为您不想刷新页面。。。 如果我错了,就别理它

$.post(url, {idx: idx, price: price, duration: duration, opt: opt}, function(data) {
        $("#content").html(data).show();
    });
return false; //Missed this line


当您从
$.post
$.ajax
提交表单时,无需在
form
中指定
onSubmit()
方法,尝试为表单提供
id
,并在
$('#myform')上执行代码。单击(函数(){})

我很抱歉回答晚了,原因是google chrome由于某种原因不允许onsubmit事件,我不得不将其更改为onclick。

表单在哪里?它在哪里提交?在chrome开发工具(选项卡控制台)中会收到什么错误消息?如果你提供完整的示例(包括html),我们可以提供更好的帮助。在切换中,你所有的
.show
都缺少括号。我会发布整个内容,但问题是我将它们都放在不同的页面中,而且它们确实很大。。我会编辑这篇文章并把它们放在那里。我想,你正在刷新页面。只需添加“返回错误”;'after'post'方法。我现在尝试了这个方法,但它在任何浏览器上都不起作用,所以我删除了它,并在post jquery之后添加了return false,它在firefox和IE上仍然有效,但在chrome上不起作用。。是的,我不想刷新页面,这就是我使用ajax的原因,尽管我很抱歉,我在Chrome上工作,我用这种方法传递数组。我不知道这对老歌是否管用,不客气。祝阿贾克斯好运。
$.post(url, {idx: idx, price: price, duration: duration, opt: opt}, function(data) {
        $("#content").html(data).show();
    });
return false; //Missed this line