douzhanjia0773
2019-04-19 01:13
浏览 56

为什么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:

enter image description here

enter image description here

图片转代码服务由CSDN问答提供 功能建议

我有一个针对PHP的AJAX请求,但是在调试函数时成功返回空格结果之前。 我无法识别给您带来的不便。 我之前已经提出过请求,但我没有遇到过这个问题。

  $('。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); 
} 
}); 
}); 
   
 
 

PHP: < pre> if(isset($ _ POST ['eliminarVEntrevista'])和isset($ _ POST ['tokenVE'])){ echo“hello”; }

答案:

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshuql24533 2019-04-19 01:51
    已采纳

    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.

    点赞 打赏 评论

相关推荐 更多相似问题