gpt4 book ai didi

从帖子返回后,Javascript 重定向不起作用

转载 作者:行者123 更新时间:2023-12-02 19:26:47 24 4
gpt4 key购买 nike

我正在使用拖放来更新用户头像,我几乎已经完成了,打赌非常非常困难,需要帮助。

我对java不太有经验..当用户拖放新图像时,它会被写入数据库并正确上传。我想做的所有事情(我认为非常简单)就是让发布窗口通过 Json 返回图像已上传,然后刷新页面以显示用户的新头像。

  <script id="template-upload" type="text/x-jquery-tmpl">
<tr class="template-upload{{if error}} ui-state-error{{/if}}">
<td class="preview"></td>
<td class="name">{{if name}}${name}{{else}}Untitled{{/if}}</td>
<td class="size">${sizef}</td>
{{if error}}
<td class="error" colspan="2"><b>Error</b> :
{{if error === 'maxFileSize'}}File too large! <br><small>(Files must be under 3Mb)</small>
{{else error === 'minFileSize'}}File too small! <br><small>(The file must be greater than 50Kb)</small>
{{else error === 'acceptFileTypes'}}Invalid file type! <br><small>(Upload pictures only)</small>
{{else error === 'maxNumberOfFiles'}}Max number of files exceeded
{{else}}${error}
{{/if}}
</td>
{{else}}
<td class="progress"><div></div></td>
<td class="start"><button>start</button></td>
{{/if}}
<td class="cancel"><button>cancel</button></td>
</tr>
</script>
<script id="template-download" type="text/x-jquery-tmpl">

<tr class="template-download{{if error}} ui-state-error{{/if}}">
{{if error}}
<td></td>
<td class="name">${name}</td>
<td class="size">${sizef}</td>
<td class="error" colspan="2"><b>Error</b> :
{{if error === 1}}File exceeds upload_max_filesize (php.ini directive)
{{else error === 2}}File exceeds MAX_FILE_SIZE (HTML form directive)
{{else error === 3}}File was only partially uploaded
{{else error === 4}}No File was uploaded
{{else error === 5}}Missing a temporary folder
{{else error === 6}}Failed to write file to disk
{{else error === 7}}File upload stopped by extension
{{else error === 'maxFileSize'}}File is too big
{{else error === 'minFileSize'}}File is too small
{{else error === 'acceptFileTypes'}}Filetype not allowed
{{else error === 'maxNumberOfFiles'}}Max number of files exceeded
{{else error === 'uploadedBytes'}}Uploaded bytes exceed file size
{{else error === 'emptyResult'}}Empty file upload result
{{else}}unknown error has occured.<br><small>(Try again later)</small>
{{/if}}

</td>
{{else}}


<td class="preview">
{{if thumbnail_url}}
THIS IS WHERE I WANT THE REDIRECT TO BE SO THAT NEW AVATAR IS DISPLAYED
<a href="${url}" target="_blank"><img src="${thumbnail_url}" width="80" height="80"></a>
{{/if}}
</td>
<td class="name">
<a href="${url}"{{if thumbnail_url}} target="_blank"{{/if}}>${name}</a>
</td>
<td class="size">${sizef}</td>
<td colspan="2"></td>
{{/if}}
<td class="delete">
<button data-type="${delete_type}" data-url="${delete_url}">Sil</button>
</td>
</tr>
</script>

最佳答案

JavaScript 重定向采用以下形式:

<script type="text/javascript">
window.location = "http://www.google.com/"
</script>

更改此:

    <td class="preview">
{{if thumbnail_url}}
{window.location("http://www.mymusicwall.co.uk/avatar.asp");}
{{/if}}
</td>

对此:

    <td class="preview">
{{if thumbnail_url}}
{<script type="text/javascript">window.location("http://www.mymusicwall.co.uk/avatar.asp");</script>}
{{/if}}
</td>

编辑

我不熟悉您的模板系统,但您需要将重定向放在模板之外。您可以将事件处理程序附加到您想要重定向的任何操作,然后按照上面在该事件处理程序中讨论的方式运行 window.location。请务必检查您的控制台是否有错误,因为我确信这是您尝试的操作不起作用的主要原因。

关于从帖子返回后,Javascript 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11960578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com