我有一个PHP脚本响应正在上传的文件。我想“回应”这个回应,但我无法让它起作用
正如您在下面的脚本中看到的,我使用了'响应',因为我无法想到任何事情。这是如何工作的?
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>';
}
答案 0 :(得分:4)
您忘记了正确连接字符串(缺少'+'):
uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:red;">Oops, something went wrong</span><br>'+response+'</center>';
答案 1 :(得分:1)
如果要在不将其添加到DOM的情况下检查响应,请使用console.log(response);
它将被记录到您浏览器的开发控制台。
答案 2 :(得分:1)
可能是指如何获取响应代码状态,代码示例:
success: function(data, textStatus, xhr) {
console.log(xhr.status);
alert(xhr.status);
},
因此,您可以根据状态代码处理响应代码并处理数据。
答案 3 :(得分:1)
这是错误:您在+
之前和之后错过了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>';