duanbaque4230 2015-02-23 14:49
浏览 23

试图让jquery显示php-script在div框中响应

First off all: I know nearly nothing about jquery (just "vanilla" javascript).

I have a simple form which sends a small text file and some parameters to the php-script which makes some changes into the file, sends it back (to the user's browser) as well as some feedback (about what was done to the file). Feedback is just a text string:

echo $feedback; // last line in my php-script

Well, it's working fine. The file-stuff part I mean. And I do get the feedback as well. But I would like to see it in the special div-box on the same page as my form is and for some reason browser keeps trasfering me to the php-script page. Here's the jquery script (I just put together from the different examples and answers in stackoverflow):

<body>
        <form id="uploadSrt" enctype="multipart/form-data" method="post" action="http://myserver/script.php">
            <input name="lyhikerida" type="text" maxlength="10" value="20"/> 
            <input id="fail" name="uploadFile" type="file"/> 
        </form> 

        <div id="kast"></div>

        <script>    
            $('#fail').change(function(){
                var frm = $('#uploadSrt');
                frm.submit(function (ev) {
                    $.ajax({
                        type: frm.attr('method'),
                        url: frm.attr('action'),
                        data: frm.serialize(),
                        success: function(response){
                            $('#kast').html(response);
                        };
                    });
                    return false;
                });
            });
        </script>
    </body>

Can you tell me, what's wrong with the script? Or is it wrong idea?

EDIT: Sorry not to mention it, but the jquery script is already at the end of the body.

EDIT2: Added the whole 'body' part (except that 'http://myserver/script.php'). Event listener seems to be working (tested with lot of 'alerts'), buts the rest of the script... it's just like it's not there. :( And switching to 'return false;' didn't change a bit.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大