用于VisualStudio的PHP工具。如何调试AJAX请求?
我有一个关于PHP的小项目,我想用用于VisualStudio的PHP工具进行调试。它工作得很好,调试器工作得很好。但我的项目中有一部分是作为服务工作的,它侦听来自html页面的AJAX请求,并以JSON格式发送响应。在这种情况下,调试器根本不起作用。我在php服务文件中设置了断点,它从不触发,但在客户端得到了正确的响应。因此,我的问题是如何使用PHP工具调试AJAX请求? 我举了一个客户端和服务器代码的例子来说明我的问题 server.php用于VisualStudio的PHP工具。如何调试AJAX请求?,php,ajax,debugging,visual-studio-2012,Php,Ajax,Debugging,Visual Studio 2012,我有一个关于PHP的小项目,我想用用于VisualStudio的PHP工具进行调试。它工作得很好,调试器工作得很好。但我的项目中有一部分是作为服务工作的,它侦听来自html页面的AJAX请求,并以JSON格式发送响应。在这种情况下,调试器根本不起作用。我在php服务文件中设置了断点,它从不触发,但在客户端得到了正确的响应。因此,我的问题是如何使用PHP工具调试AJAX请求? 我举了一个客户端和服务器代码的例子来说明我的问题 server.php <?php if(isset($_REQU
<?php
if(isset($_REQUEST['response'])) {
echo json_encode('ok');
}
else {
echo json_encode('cancel');
}
?>
client.html
<!DOCTYPE HTML>
<html>
<head>
<title>AJAX test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$( "#request" ).bind( "click", function() {
var data = { response: "response" };
$.ajax({
url: "server.php",
type: "POST",
async: false,
timeout: 5000,
dataType: "json",
data: data,
success: function(result) {
$("#response").text(result);
},
error: function(error) {
$("#response").html(error.responseText);
}
});
});
});
</script>
</head>
<body>
<p>
<b>Request: </b> <span id="request"><a href="#">Send request</a></span>
</p>
<p>
<b>Response: </b> <span id="response">Here will be your response...</span>
</p>
</body>
</html>
AJAX测试
$(文档).ready(函数(){
$(“#请求”).bind(“单击”,函数(){
var data={response:“response”};
$.ajax({
url:“server.php”,
类型:“POST”,
async:false,
超时:5000,
数据类型:“json”,
数据:数据,
成功:功能(结果){
$(“#答复”)。文本(结果);
},
错误:函数(错误){
$(“#response”).html(error.responseText);
}
});
});
});
请求:
回复:以下是您的回复。。。
因此,当我在server.php的if语句行上设置断点时,它不会触发,但客户端成功地接收到服务器响应。我在 在这种情况下,xdebug不知道什么时候应该开始调试。Easist方法是在下一行添加到php.ini:
xdebug.remote_autostart = on
一切都好 请注意,Xdebug v3(支持?
远程自动启动
)。链接的升级文档显示“xdebug.remote\u autostart设置已被删除。相反,将xdebug.start\u with\u request设置为yes
”指向文档的链接(xdebug 2和3)-