0

こんにちは、私のコードです..

<html>
<head>   
<script src="http://code.jquery.com/jquery-1.8.0.min.js">
</script>
</head>  
<body> 
<form id="foo">

    <label for="bar">A bar</label>
    <input id="bar" name="bar" type="text" value="" />

    <input type="submit" value="Send" />

</form>  
<div id ="onsuccess">      
</div>   
<script>  
// variable to hold request
var request;
// bind to the submit event of our form
$("#foo").submit(function(event){   
    var $form = $(this);
    var serializedData = $form.serialize();
    request = $.ajax({
        url: "a.txt",
        type: "post",
        dataType: "text", 
        data: serializedData,
        success: function(){ 
        console.log("yes, its successful");},
        error : function(){console.log("got an error");}
    });
});

</script>
</body> 
</html>

同じディレクトリにある a.txt にアクセスしようとしていますが、成功とエラーの機能が呼び出されず、理解できません。Firebug ネットステータスは、呼び出しが行われなかったことを示しています.strange

しかし、私が使用する場合

request.done(function (response, textStatus, jqXHR){
        // log a message to the console
        console.log("Hooray, it worked!");
        //$("#success").html(response);
    });

それは機能します。

4

2 に答える 2