【发布时间】:2015-11-23 21:01:23
【问题描述】:
我正在尝试获取一个表单以在不打开 IP 地址的情况下向 IP 地址提交操作。
所以,当我点击提交按钮时,我希望它发送 post 命令到 ip(在本例中为 192.168.0.1)并刷新当前页面。
<div data-role="main" class="ui-content">
<form method="POST" action="http://192.168.0.1/">
<input type="submit" name="parser" value="thisguy"/>
</form>
</div>
我在提交时运行的脚本:
<script src="http://ajax.googleapis.com/ajax/liubs/jquery/1.9.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$('form.ajax').on('submit', function() {
var that = $(this),
url = that.attr('action'),
method = that.attr('method'),
data - {};
that.find('[name]').each(function() {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
$.ajax({
url: url,
type: method:,
data: data,
success: function(response) {}
});
});
return false;
});
</script>
现在它提交帖子并尝试将 192.168.0.1 作为网页打开。有人可以通过提供带有解释的代码或将我指向命令来帮助我吗?
感谢任何帮助。
【问题讨论】:
-
你的代码中有一个 type-o,在 "type: method:," 一个额外的冒号
-
为什么在通过 ajax 发送请求时使用表单?
-
那条
data - {}行又是怎么回事?问这个问题之前你用过JSHint吗? -
如果您将 preventdefault() 添加到您的 ajax 函数中,页面将不会/需要刷新。如果您确实希望页面刷新,您可以在 ajax req 完成后编写 location =location。
-
@Xufox 我还没有,我现在正在运行代码!谢谢!
标签: javascript jquery ajax html forms