On the google App Engine, I would like to use Javascript (or Ajax) to POST a form and then update the target div. The form contains a lot of fields and files to transfer. The Javascript function is copied from the "Javascript: The Definite Guide" book. I have 2 questions:
How to design the callback function, so that the response (i.e., "form.html") may update the content div?
如何设计回调函数,以便响应(即“form.html”)可以更新内容div?
Thanks for your help.
谢谢你的帮助。
base.html:
base.html文件:
...
{% include "form.html" %}
Image:
...
form.html
form.html
name1: {{ name1 }}
name2: {{ name }}
...
file1: {{ file1 }}
file2: {{ file2 }}
...
3 个解决方案
#1
1
When you do a Form POST (user clicks submit button or called via JS) then browser will reload the window and display the result of the POST. This is obviously not what you want.
$(document).ready(function()
{
$('.submit').on('click', function()
{
if($(".name").val()==""){
$(".name").val("Enter Name Here")
}
else {
var s = $(".name").val();
var n = $(".imageform").attr("action");
$(".imageform").attr("action", function() {
return s+n;
}
$("#callback").html('Uploading.....');
$(".imageform").ajaxForm(
{
target: '#callback'
}).submit();
}
});
});
also include this link in head:
还包括这个链接:
hey man all the text which will echo in php file will be shown in #callback. So, if you want to preview image please echo there html and do not remove that action=/form/index.php?name= and also in php file type $name=$_GET['name'];
嘿,所有将在php文件中回显的文本将显示在#callback中。所以,如果你想要预览图像,请回显那里的html,不要删除那个动作= / form / index.php?name =和php文件类型$ name = $ _ GET ['name'];
#3
0
I came up with the following code. But, strangely, it worked sometimes, other times it didn't. When it failed, the error message displayed in Firebug was "ReferenceError: $ is not defined". Can somebody tell me what the problem is and if this is a correct solution? Thanks.
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(function(returnData) {
$('#content').html(returnData)
});
});
本文详细解析了JSONP(JSON with Padding)的跨域机制及其工作原理。JSONP是一种通过动态创建``标签来实现跨域请求的技术,其核心在于利用了浏览器对``标签的宽松同源策略。文章不仅介绍了JSONP的产生背景,还深入探讨了其具体实现过程,包括如何构造请求、服务器端如何响应以及客户端如何处理返回的数据。此外,还分析了JSONP的优势和局限性,帮助读者全面理解这一技术在现代Web开发中的应用。 ...
[详细]
本文详细介绍了一种利用 ESP8266 01S 模块构建 Web 服务器的成功实践方案。通过具体的代码示例和详细的步骤说明,帮助读者快速掌握该模块的使用方法。在疫情期间,作者重新审视并研究了这一未被充分利用的模块,最终成功实现了 Web 服务器的功能。本文不仅提供了完整的代码实现,还涵盖了调试过程中遇到的常见问题及其解决方法,为初学者提供了宝贵的参考。 ...
[详细]