我有一個index.html文件,它包含一個觸發ajax請求並啓動php文件的按鈕。php文件將數據發送到服務器。問題是我不知道如何調試php文件,因爲echo似乎不起作用(我可能做錯了)。我只是想將各種變量回顯到html文件中的div中,並在程序中的不同位置查看它們的含義。如果有更好的方法來做到這一點,請發佈。謝謝。如何調試發生ajax事件時啓動的php
PHP
<?php
require_once 'connect.php';
?>
<?php
// Create table
$patchData = $_POST[mydata];
$encoded = json_encode($patchData);
$sql="INSERT INTO patches (patch_name)
VALUES ('{$encoded}')";
// Execute query
if (mysqli_query($con,$sql))
{
echo "Table updated successfully";
}
else
{
echo "Error updating table: " . mysqli_error($con);
}
?>
的Javascript
var patch = {
"patch_name": "",
"sound_type": {
"synths": [ // each 'synth name' is a draggable div that plays an oscillator
// etc
],
"samplers": [
// same as synth only for divs that trigger audio files instead of oscillators
]
},
}
// START Save DOM nodes
function save(){
instrumentName = $('#instrument-name-form').val();
patch.sound_type.synths.length = 0;
patch.sound_type.samplers.length = 0;
$(".synth").each(function(){
var temp = $("#" + this.id);
var pos = $(temp).position();
console.log(this.id);
patch.sound_type.synths.push({'synth_name':this.id,'xpos':pos.left,'ypos':pos.top});
});
$('.patch-list').html(patch.name);
patch.patch_name = instrumentName ;
console.log(patch);
$.ajax({
type: 'POST',
url: 'php/add.php',
data: {mydata: patch},
success: function(){
console.log('yay');
}
});
};
$('#save-synths').click(function(){
save();
})
echo然後firebug,你會在網絡面板看到輸出,或調試到文件,錯誤日誌,甚至電子郵件 – 2013-10-19 20:36:44
你可以發佈你的代碼 –
我使用的是Chrome。代碼發佈。 – William