Javascript 表单数据从jquery发布到Google应用程序引擎不起作用
我正在开发一个简单的jquery应用程序,我想做的是将Javascript 表单数据从jquery发布到Google应用程序引擎不起作用,javascript,jquery,python,google-app-engine,jquery-mobile,Javascript,Jquery,Python,Google App Engine,Jquery Mobile,我正在开发一个简单的jquery应用程序,我想做的是将用户名和名称从表单发布到Google应用程序引擎。但当我在表单中单击addEmpBtn时,什么都没有发生 这是接受数据和提交按钮的表单 <form id="post" action="http://localhost:8070/addNewEmployee" method="post"> <input id="username" name="user" placeholder="Username" type=
用户名
和名称
从表单发布到Google应用程序引擎。但当我在表单中单击addEmpBtn
时,什么都没有发生
这是接受数据和提交按钮的表单
<form id="post" action="http://localhost:8070/addNewEmployee" method="post">
<input id="username" name="user" placeholder="Username" type="text" size="30"/>
<input id="name" name="name" placeholder="Name" type="text" size="30"/>
<a href="#" id="addEmpBtn" data-theme="b" data-role="button" data-inline="true">Register</a>
</form>
我正在使用Webstorm
编写jQuery移动代码,我的项目目录结构如下所示
application: get-post-test
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /html
static_dir: html
- url: /js
static_dir: js
- url: /png
static_dir: imgs
- url: /.*
script: main.app
最后,这就是staff_game.js
文件的外观
URL = "http://localhost:8070/addNewEmployee";
$(document).ready( function() {
$("#addEmpBtn").bind('click', function(event){
addNewEmployee();
event.preventDefault();
});
});
function doPostRequest(postData) {
$.ajax({
type: "POST",
url: URL,
data: postData,
dataType: "json"
}).done(function(data, textStatus, jqXHR){
// This clears out the message sent.
$("#username").val('');
$("#name").val('');
setTimeout(doGetRequest, 1000);
}).always(function(data, textStatus){
});
}
function addNewEmployee() {
//Encode the user-id and message as a single JSON
// object, in name:value pairs...
var struser=$("#username").val(),
strmessage=$("#name").val(),
postData = {username: struser, name: strmessage};
// Now use this data in a POST operation...
doPostRequest(postData);
}
由于没有显示任何错误消息,我无法判断出哪里出了问题。我甚至不确定我是否正确配置了YAML
文件。
因为当我尝试像
localhost:8070/js/staff\u game.js
什么也没发生。但我在某个地方读到,这应该返回javascript(?)中的内容。
我需要先申报舱单吗?如果是,怎么做?我做错了什么?在我看来,您至少在
之后缺少了一个括号。始终(函数(数据,文本状态){}doPostRequest
函数中的
。如果你的js有语法错误,那么你的事件处理程序都不会被绑定,你的按钮只是指向#
的链接,实际上什么都没有。我已经纠正了这一点,我在编辑问题时丢失了括号。要调试你的javascript发送函数,你能添加su吗在ajax中访问并完成methode,查看其中一个是否响应。为什么a)硬编码完整URL,b)使用非默认端口:8070?您是否专门使用8070启动devappserver?即使是这样,也不应该硬编码,而应该使用相对路径(URL=“/addNewEmployee”
)等。创建一个自包含的示例(向处理程序发送一篇简单的帖子)可能是一个好主意,然后将该示例扩展到您需要的功能。webapp2教程可能是开始的地方: