简体   繁体   English

打印Javascript响应

[英]Print Javascript Response

I have a php script that responds to a file being uploaded. 我有一个php脚本来响应正在上传的文件。 I want to 'echo' this response but I can't get it to work 我想回显此响应,但无法正常工作

As you can see in the script below I used ' response ' because I couldn't think of anything. 正如您在下面的脚本中看到的那样,我使用了“ response”,因为我什么都没想到。 How does this work? 这是如何运作的?

success:function(response){
    if(response == 6563){
        var uploaddiv = document.getElementById('uploadattachment');
        uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:green;">File has successfully been uploaded.</span><br>You can now click this window away or upload another file</center>';
    } else {
        var uploaddiv = document.getElementById('uploadattachment');
        uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:red;">Oops, something went wrong</span><br>' response '</center>';
    }

您忘记正确连接字符串(缺少“ +”):

uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:red;">Oops, something went wrong</span><br>'+response+'</center>';

If you want to inspect the response without adding it to the DOM, use console.log(response); 如果要检查响应而不将其添加到DOM,请使用console.log(response); and it will be logged to the developed console of your browser. 它将记录到浏览器的开发控制台中。

May be you mean how to get response code status, code sample: 可能是您的意思是如何获取响应代码状态,代码示例:

   success: function(data, textStatus, xhr) {
       console.log(xhr.status);
       alert(xhr.status);
   },

So you can handle the response code and process your data according to the status code. 因此,您可以处理响应代码并根据状态代码处理数据。

This is the error: You missed a + after and before the response . 这是错误:您在response之前和之后错过了一个+

var uploaddiv = document.getElementById('uploadattachment');
uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:red;">Oops, something went wrong</span><br>' + response + '</center>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM