抓住ajax得到错误

Ven*_*raj -2 javascript ajax jquery get

我有以下javascript函数ajax $.get.

function make_draggable(elements)
{
    /* Elements is a jquery object: */

    elements.draggable({
        containment:'parent',
        start:function(e,ui){ ui.helper.css('z-index',++zIndex); },
        stop:function(e,ui){

            /* Sending the z-index and positon of the note to update_position.php via AJAX GET: */


            $.get('ajax/update_position.php',{
                  x     : ui.position.left,
                  y     : ui.position.top,
                  z     : zIndex,
                  id    : parseInt(ui.helper.find('span.data').html())
            });

        }
    });
}
Run Code Online (Sandbox Code Playgroud)

但遗憾的是我的申请无效.我想抓住ajax错误.任何帮助都会非常有帮助.

Que*_*tin 5

请参阅文档.$.get返回一个jqxhr对象,您可以调用该对象fail并传递回调.

$.get(etc).fail(function (jqXHR, textStatus, errorThrown) {
    alert("There was an error. Look in the browser's JS console for details.");  
    console.log(jqXHR);
    console.log(textStatus);
    console.log(errorThrown);
});
Run Code Online (Sandbox Code Playgroud)