为什么AJAX成功更喜欢结果中的空格?
I have an AJAX request towards PHP, but when debugging the function success is returning empty spaces before the result. I can not identify the inconvenience. I have already made requests before and I had not had this problem.
$('.eliminarve').click(function() {
var token = $(this).attr('id');
var datos = new FormData();
datos.append('eliminarVEntrevista', true);
datos.append('tokenVE', token);
$.ajax({
url: "../../views/ajax.php",
method: "POST",
data: datos,
processData: false,
contentType: false,
cache: false,
beforeSend: function() {
$("#loading").removeClass('d-none');
},
success: function(result, status, xhr) {
$("#loading").addClass('d-none');
console.log(result);
console.log(status);
console.log(xhr);
//alert(retorno);
}
});
});
PHP:
if (isset($_POST['eliminarVEntrevista']) and isset($_POST['tokenVE'])) {
echo "hello";
}
Answer:
我有一个针对PHP的AJAX请求,但是在调试函数时成功返回空格 strong >结果之前。 我无法识别给您带来的不便。
我之前已经提出过请求,但我没有遇到过这个问题。 p>
PHP: p>
答案: p>
$('。eliminarve')。click(function(){
var token = $(this).attr('id');
var datos = new FormData();
datos.append('eliminarVEntrevista',true);
datos.append('tokenVE', token);
$ .ajax({
url:“../../ views / ajax.php”,
n方法:“POST”,
data:datos,
processData:false,
contentType:false,
cache:false,
beforeSend:function(){
$(“#loading”)。removeClass('d-none');
},
success:function(result,status ,xhr){
$(“#loading”)。addClass('d-none');
console.log(result);
console.log(status);
console.log(xhr);
// alert(retorno);
}
});
});
code> pre>
if(isset($ _ POST ['eliminarVEntrevista'])和isset($ _ POST ['tokenVE'])){
echo“hello”;
}
code> pre>
Sounds like the editor you're using is adding /n
or another new line hidden character to your output. Open the file in something like Notepad++ to check if there are any hidden (or special) characters in the file.