Php 如何修复此代码以在上载后显示正确的消息?
我在下面有一段代码,它检查文件是否上载成功、未成功或已取消:Php 如何修复此代码以在上载后显示正确的消息?,php,javascript,jquery,Php,Javascript,Jquery,我在下面有一段代码,它检查文件是否上载成功、未成功或已取消: if (success === 1){ result = '<span class="imagemsg'+imagecounter+'">The file was uploaded successfully</span><br/><br/>'; $('.listImage').eq(window.lastUploadImageIndex).append
if (success === 1){
result = '<span class="imagemsg'+imagecounter+'">The file was uploaded successfully</span><br/><br/>';
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
displayInfo = replaceForm;
}
else if (success === 2){
result = '<span class="imagemsg'+imagecounter+'"> The file upload was canceled</span><br/><br/>';
displayInfo = updateForm;
}
else {
result = '<span class="imagemsg'+imagecounter+'">There was an error during file upload</span><br/><br/>';
displayInfo = updateForm;
}
if(success==1){
结果='文件已成功上载
';
$('.listImage').eq(window.lastUploadImageIndex).append(''+htmlEncode(imagefilename)+'Remove
);
displayInfo=replaceForm;
}
如果(成功===2){
结果='文件上载已取消
';
displayInfo=updateForm;
}
否则{
结果='文件上载过程中出现错误
';
displayInfo=updateForm;
}
但我有一个JavaScript函数,它在PHP脚本中输出以下内容:
<script language="javascript" type="text/javascript">
window.top.stopImageUpload(<?php echo $result ? 1 : 2; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');
</script>
window.top.stopImageUpload(,'');
现在,如果文件上载成功,将显示正确的消息,如果已取消,将显示正确的mssage,但问题是,如果文件未能上载,则会显示取消消息,而不是上载消息时的错误。我尝试更改上述代码的一部分,使其如下所示:
…..
但这给了我一个错误。我的问题是如何更改上述代码,以便在文件未能成功上载时能够输出正确的消息?错误是什么
您的三元语法不正确:
正确的语法是:
echo ( <condition> ) ? <event if true> : <event if false>;
echo()?:;
你有额外的活动
$result?1:2:3
不是有效的速记如果
语法。@ColorWP.com我是说$result?1 : 2 : 3;代码>但这不起作用,就像你说的,它将无效
$.ajax(
{
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/Web/Lists/getByTitle('" + libTitle + "')/Items",
type: "GET",
contentType: "application/json;odata=verbose",
headers: {
'Accept': 'application/json;odata=verbose',
'X-RequestDigest': $("#__REQUESTDIGEST").val()
},
success: fetchSuccess,
error: onFailure
});
function fetchSuccess(r) {
// How to display the count of "r"
console.log(r.length);
}
function onFailure(r) {
alert("Error + r + working");
}