1

リンクをクリックすると、ajax POST リクエストが起動されます。私はこれをします:

$('a#create_object').click();

これにより、ajax リクエストが発生します。この ( $.ajax({...})) のコードは、ブートストラップ ライブラリのどこかに書かれており、編集したくありません。

ajaxが成功した後、リクエストのレスポンスにアクセスするにはどうすればよいですか?

4

2 に答える 2

1

ダイレクト コールバックは jQuery 1.8.0 以降非推奨ですが、.done、.fail、および .always コールバックを使用できます。

そして、何かをしたい場合は、コールバックを上書き/アクセスする必要があります。つまり、外部からアクセスすることはできません!

$('#link').on('click', function(e) {
    $.ajax({
        type: "post",
        url: "your-page",
        data: {},
        dataType: "json"
    }).done(function (response) {
        alert('Success');
        console.log(response); // Use it here
    }).fail(function (response) {
        alert('Fail');
        console.log(response); // Use it here
    }).always(function (response) {
        // Here manage something every-time, when it's done OR failed.
    });
});
于 2013-04-25T13:02:09.047 に答える
0
$('#controlId').click(function(){ $.ajax({
        type: "POST",
        url: "PageUrl/Function",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
        alert(response.d); //here you can get the response on success of function
        }
    });
});
于 2013-04-25T13:01:16.150 に答える