実行時に呼び出されるページは$.getJSON()
、スクリプトを呼び出すたびに(ユーザーがリンク/ボタンをクリックしたときに)そのジョブを実行しますが、それに関連付けられた関数は何も実行しません。これはScript.php
ファイル内にあります:
$('a.addCategorie').click(function (e)
{
e.preventDefault();
var dialog='<div id="Dialog_AddCategory">\
<div id="tableContainer">\
<table class="categoryTable">\
<thead>\
<tr>\
<th>Ordre</th>\
<th>Catégorie</th>\
<th> </th>\
</tr>\
</thead>\
<tbody>\
<?php
$sql="SELECT nom, ordre FROM category ORDER BY ordre";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>". $row['ordre'] ."</td>";
echo "<td>". utf8_decode($row['nom']) ."</td>";
echo "<td id=\"" . $row['ordre'] . "\" class=\"deleteCat\"></td>";
echo "</tr>\\\n";
}
?>
</tbody>\
</table></div>\
<div id="addCategorie_Form">\
<form>\
<label for="nomCategorie">Nom de la catégorie</label>\
<input type="text" name="nomCategorie" id="nomCategorie"/>\
<label for="ordreCategorie">Ordre</label>\
<input type="text" name="ordreCategorie" id="ordreCategorie"/>\
</form>\
</div></div>';
$('body').append(dialog);
$( '#Dialog_AddCategory' ).dialog({
autoOpen: false,
modal: true,
width: 800,
height: 400,
open: function(even, ui) { $(".ui-dialog-titlebar-close", ui.dialog).css("visibility","hidden");},
title: "Nouvelle catégorie",
resizable: false,
hide:'slide',
show:'slide',
buttons:
{
"Créer la catégorie":function()
{
var ok = true;
if(isNaN($('#ordreCategorie').val()) || $('#ordreCategorie').val().length < 1)
{
ok = false;
$('#ordreCategorie').css("background-color","#F00");
}
else
{
$('#ordreCategorie').css("background-color","#CF0");
}
if($('#nomCategorie').val().length< 3)
{
ok = false;
$('#nomCategorie').css("background-color","#F00");
}
else
{
$('#nomCategorie').css("background-color","#CF0");
}
if(ok)
{
var ordre = $('#ordreCategorie').val();
var nom = $('#nomCategorie').val();
$.getJSON('addCategory.php', {'ordre':ordre,'nom':nom}, function(data)
{
console.log("THIS LOG WON'T APPEAR AND THE CODE WON'T EXECUTE.");
if( data.result === "false" )
{
$('div id="Dialog_Feedback">Une catégorie porte déjà ce nom ou cet ordre!</div>').dialog(
{
autoOpen:false,
title:'Une erreur est survenue!',
width:200,
height:'auto',
resizable: false,
modal:true,
buttons:
{
"OK" : function()
{
$( this ).remove();
}
}
});
}
else
{
$('<div id="Dialog_Feedback">L\'ajout a été effectué avec succès!</div>').dialog({
autoOpen:false,
title:'Catégorie ajoutée!',
width:400,
height:'auto',
resizable:false,
modal:true,
buttons:{
"Ok": function()
{
$(this).remove();
window.location.reload();
}
}
});
}
$('#Dialog_Feedback').dialog("open");
});
}
},
"Annuler":function()
{
$( this ).remove();
}
}
});
これがaddCategory.php
ページです:
<?php
include('../../anything.php');
$nom = $_GET['nom'];
$ordre = $_GET['ordre'];
$sql = "SELECT ordre, nom FROM category";
$checking = mysql_query($sql);
$ok = true;
while ($row=mysql_fetch_array($checking))
{
echo "test";
if((strtolower($nom) === strtolower($row['nom'])) || ($ordre === $row['ordre']))
{
$ok = false;
}
}
if ($ok)
{
$sql = "INSERT INTO category (nom,ordre) VALUES('$nom',$ordre)";
$result = mysql_query($sql);
mysql_close($connexion);
echo json_encode(array("result"=>"true"));
}
else
{
echo json_encode(array("result"=>"false"));
}
?>
誰もがそれを引き起こす可能性があるものの考えを持っていますか?GETで送信された両方の変数を確認しましたが、それらには何かが含まれています。
私のPHPページは、次のようなJSONエンコードされた結果を返します。
echo json_encode(array("result"=>"true"));
みなさん、ありがとうございました。
編集:ChromeInspectorとFirebugの両方がスクリプト実行全体でエラーを報告しないことを言及するのを忘れました。このconsole.log()
部分も表示されません。つまり、PHPページのコマンドは実行されますが、内部に含まれるjavascript関数$.get()
はトリガーされません。
Edit2:とへの呼び出しも変更してみましecho
た。echo true;
return true;
Edit3:Chrome Inspectorの[ネットワーク]タブでPHPページの結果を確認できます。Firebug:{"result":"false"}array(1) {
["result"]=>
string(5) "false"
}
問題が$.getJSON()
通話にあることを示しています。しかし、私にはすべてがうまくいくようです!