AJAX POST处理程序引起"未捕获的异常" [英] AJAX POST handler causing "uncaught exception"

查看:112
本文介绍了AJAX POST处理程序引起"未捕获的异常"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在敲打我的头靠在我的办公桌上了几个小时就这一个,我没有得到任何地方,所以帮助真的会AP preciated。

在code以下具有火了一个Ajax请求2个jQuery的事件处理程序。第一个使用GET,它会从服务器返回的数据为JSON EN codeD - 它工作正常。第二个(按钮#addTx)收益使得萤火虫产生这种错误:

  

未捕获的异常:[异常...   提示中止用户nsresult:   0x80040111(NS_ERROR_NOT_AVAILABLE)   位置:JS框架::   资源://gre/components/nsPrompter.js   :: openTabPrompt ::行468的数据:   否]

     

行0

这是没有任何帮助的。服务器端脚本是印刷原始HTML到屏幕和目标是,一个jquery的html替换将被用于更新到发起请求的页面。该数据被正确地张贴数据库更新,但除此之外,我没有任何线索。我已经重写它尝试GET,仍然产生了同样的错误: - (

帮助将是惊人的 - 谢谢你,西蒙

  $(文件)。就绪(函数(){
$(button.delete)。点击(函数(){
    VAR TxID添加= this.id;
    VAR amountID =#amount+ TxID添加;
    VAR金额= $(amountID)。html的();
    //<![CDATA [

    VAR URL =delete.php TxID添加=?+ TxID添加+&放大器; AM =+量;
    $阿贾克斯({
        键入:GET,
        网址:网址,
        成功:函数(MSG){
            TxID添加=UL#+ TxID添加;
            $(TxID添加).hide();

            VAR值=味精;
            变种E =#+ values​​.category +AmountLeft;
            VAR一个= values​​.amount;

            $(E)的.html(一);
        }
    });
});
$(#键addTx)。点击(函数(){

    //<![CDATA [


    VAR URL =addTran.php;
    // VAR dataV = VAR数据=类=+的document.getElementById(类)的值+&放大器;什么=+的document.getElementById(什么)值+。&放大器;金额=+文档。.getElementById(额)值+&放大器;日期=+的document.getElementById(日)的价值;
    $阿贾克斯({
        键入:POST,
        网址:addTran.php
        //异步:​​假的,
        数据:分类=杂货和放大器;什么=食品与量= 2.33和放大器;日期= 2/3/2011,
        成功:函数(MSG){
            $(transList)replaceWith(MSG)。
        }
    });
});
});
 

和这里是服务器端脚本

 < PHP
在session_start();
包括:('的functions.php');
//如果用户没有登录
如果(!isLoggedIn())
{
    标题(位置:的index.php);
    死();
}


$类别= $ _ POST ['类'];
$什么= $ _ POST ['什么'];
$金额= $ _ POST ['量'];
$日期= $ _ POST ['日期'];

$类别= mysql_real_escape_string($类);
$什么= mysql_real_escape_string($什么的);
$金额= mysql_real_escape_string($金额);
$日期= mysql_real_escape_string($日期);

$日期= convertDate($日期);

//添加反式DB
包括('dbcon.php');
$查询=INSERT INTO事务(类,什么的,金额,日期)VALUES('$类,$什么,$量','$日期);;
的mysql_query($查询);

//从预算攫取剩余量
$查询=选择amount_left贺卡那些类别='$类;;
$结果= mysql_query($查询);
$行= mysql_fetch_array($结果,MYSQL_ASSOC);
$ oldAmountLeft = $行[amount_left];

//更新剩余的数额
$ amountLeft = $ oldAmountLeft  -  $金额;

了mysql_free_result($结果);

//增加新的价值分贝
$查询=UPDATE卡SET amount_left ='$ amountLeft'WHERE类='$类;;
的mysql_query($查询);



//生成剩余交易清单,打印到屏幕传送回主画面

$查询=选择TxID添加什么​​,金额,日期从交易WHERE类别=('$类');;
$结果= mysql_query($查询);

而($行= mysql_fetch_array($结果,MYSQL_ASSOC)){
    $ D = convertDateReverse($行[日]);
    $内容= $行[是什么];
    $金额= $行[数量];
    $ TxID添加= $行[TxID添加];
    ?>
        <李>< UL类=跨ID =&LT ;?回声$ TxID添加;>中><李类=约会>&LT ;?回声$ D; ?>< /李><李类=什么>&LT ;?回声$的东西; ?>< /李><李类=量ID =度<?回声$ TxID添加;>中>&LT ;?回声$数额; ?>< /李><按钮类=删除ID =&LT ;?回声$ TxID添加;>中>删除< /按钮><李>< /李>< / UL&GT ;< /李>
    &LT ;?
}
了mysql_free_result($结果);



则mysql_close();

标题(内容类型:应用程序/ x-WWW的形式urlen codeD); //我需要这个?在工作​​之一;:我有一个标题(应用/ JSON内容类型)

?>
 

解决方案

问题解决了:这样的HTML标记保存数据的领域应该有一个形式

 的onsubmit =返回false;
 

在它!

感谢所有帮助家伙,我已经实现了所有的建议和我的code是现在SOOOO更小,更容易管理!

干杯

西蒙

So I've been banging my head against my desk for a few hours on this one and i'm not getting anywhere so help would really be appreciated.

The code below has two jquery event handlers which fire off an ajax request. The first one uses GET and the data it gets back from the server is JSON encoded - it works fine. The second one ( "button#addTx" ) returns causes Firebug to produce this error:

uncaught exception: [Exception... "prompt aborted by user" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: resource://gre/components/nsPrompter.js :: openTabPrompt :: line 468" data: no]

Line 0

which is no help to at all. The server side script is printing raw html to the screen and the aim is that a jquery html replace will be used to update to the page which initiates the request. The data is POSTed correctly as the database updates but beyond that I have no clue. I have rewritten it to try a GET and still produce the same error :-(

Help would be amazing - thank you, Simon

$(document).ready(function(){
$("button.delete").click(function(){
    var txid = this.id;
    var amountID = "#amount" + txid;
    var amount = $(amountID).html();
    // <![CDATA[

    var url = "delete.php?txid=" + txid + "&am=" + amount;
    $.ajax({
        type: "GET",
        url: url,
        success: function(msg){
            txid = "ul#" + txid;
            $(txid).hide();

            var values = msg;
            var e = "#" + values.category + "AmountLeft";
            var a = values.amount;

            $(e).html(a);
        }
    });
});
$("button#addTx").click(function(){

    // <![CDATA[


    var url = "addTran.php";
    //var dataV = var data = "category=" + document.getElementById("category").value + "&what=" + document.getElementById("what").value + "&amount=" + document.getElementById("amount").value + "&date=" + document.getElementById("date").value;
    $.ajax({
        type: "POST",
        url: "addTran.php",
        //async: false,
        data: "category=Groceries&what=Food&amount=2.33&date=2/3/2011",
        success: function(msg){
            $("transList").replaceWith(msg);
        }
    });
});
});

and here is the server side script

<?php
session_start();
include('functions.php');
//if the user has not logged in
if(!isLoggedIn())
{
    header('Location: index.php');
    die();
}


$category = $_POST['category'];
$what = $_POST['what'];
$amount = $_POST['amount'];
$date = $_POST['date'];

$category = mysql_real_escape_string($category);
$what = mysql_real_escape_string($what);
$amount = mysql_real_escape_string($amount);
$date = mysql_real_escape_string($date);

$date = convertDate($date);

//add trans to db
include('dbcon.php');
$query = "INSERT INTO transactions ( category, what, amount, date) VALUES ( '$category','$what','$amount','$date');";
mysql_query($query);

//grab the remaining amount from that budget
$query = "SELECT amount_left FROM cards WHERE category = '$category';";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$oldAmountLeft =  $row["amount_left"];

//update the amount left
$amountLeft = $oldAmountLeft - $amount;

mysql_free_result($result);

//add new value to db
$query = "UPDATE cards SET amount_left = '$amountLeft' WHERE category = '$category';";
mysql_query($query);



//generate the list of remaining transactions, print to screen to send back to main page

$query = "SELECT txid, what, amount, date FROM transactions WHERE category = ('$category');";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $d = convertDateReverse($row["date"]);
    $what = $row["what"];
    $amount = $row["amount"];
    $txid = $row["txid"];
    ?>
        <li><ul class="trans" id="<? echo $txid; ?>"><li class="date"><? echo $d; ?></li><li class="what"><? echo $what; ?></li><li class="amount" id="amount<? echo $txid; ?>"><? echo $amount; ?></li><button class="delete" id="<? echo $txid; ?>">Delete</button><li></li></ul></li>
    <?
}
mysql_free_result($result);



mysql_close();

header("Content-type: application/x-www-form-urlencoded"); //do I need this? I have a " header("Content-type: application/json"); " in the working one

?>

解决方案

PROBLEM SOLVED: so in the html markup the form that holds the fields of data should have an

onsubmit="return false;"

in it!

Thanks for all the help guys, I have implemented all your suggestions and my code is now soooo much smaller and easier to manage!

Cheers

Simon

这篇关于AJAX POST处理程序引起&QUOT;未捕获的异常&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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