私はこの簡単な例を使って質問を詳しく説明しました。投稿のリクエストを行ったファイルからDOMを取得する
$(document).ready(function()
{
$(#submit).click(function()
{
$var = $("#result");
$code = $("#code");
$.post("ajax.php", {option : $var, code: $code}, function()
{
//Getting through the DOM could be useful if you want to analyse the answer coming from the ajax.php file
var $DOMresponse = getElementByTagName("div")[0].firstChild.data; // I would want the correct code here because this is incorrect... this is ti give you an idea
if($DOMresponse == "your code is correct")
{
$("#container1").fadeOut(400, function(){ $("#container1").html(result); });
$("#container1").fadeIn();
}
elseif($DOMresponse == "your code is incorrect. Go again trough the procedure")
{
$("#container2").fadeOut(400, function(){ $("#container2").html(result); });
$("#container2").fadeIn();
}
// In this second case I could fill the second container id="container2"
});
});
});
ajax.php例:
<?php
if($_POST['request']==1)
{
if($_POST['code']==$user['code'])
{
?><img src="...">
<div>tomatoes</div>
<div>potatoes</div>
<div id="answer">your code is correct</div> <?php
}
else
{
?><img src="...">
<div>apples</div>
<div>oranges</div>
<div>your code is incorrect. Go again trough the procedure</div> <?php
}
}
私はajax.phpファイルのDOMを介して取得する方法を知りたい
は、Ajaxの下に次のPOSTリクエストを与えられました。
どうすればよいですか?ありがとう
あなたの答えをありがとう、私はあなたが言っていることをする必要はありません...私はする必要がありますjavascript内で "あなたのコードは正しい"または "自分のコードが間違っています"という応答を認識するためにDOMを通過します。両方の人が助言しているからです。> javascriptは応答を認識しません。javascriptは解析やckeckingなしで答えを出すだけです。これどうやってやるの? –
私は尋ねたいものをより良く説明するために少し例を変更しました!お返事ありがとう –