【发布时间】:2013-02-20 06:10:32
【问题描述】:
如何在不使用 HTML 表单的情况下提交表单数据。
我只需要向 example.php 发送 1 个输入,并且希望远离 ajax/jQuery。
也可以在后台发送它而不重定向/刷新页面。
下面的代码是我所得到的。我希望它发送input_1,它的价值value 1
一旦页面加载到example.php 而没有页面重定向。
theForm = document.createElement('form');
theForm.action = 'example.php';
theForm.method = 'post';
newInput1 = document.createElement('input');
newInput1.type = 'hidden';
newInput1.name = 'input_1';
newInput1.value = 'value 1';
【问题讨论】:
-
支持 JavaScript 但不支持 AJAX 的设备? AJAX 主要是 JavaScript!
-
@ShivanRaptor 我很抱歉需要解决这个问题,使用 jQuery 确实存在错误,所以我宁愿把它留给 javascript
-
没有重定向到 example.php 你不能。您应该尝试通过简单的 xhr 请求设备是否支持 ajax。查找跨浏览器 xhr。
-
目前支持 jQuery 的设备种类繁多。您使用的是什么类型的设备?
-
@Prasanth first answer stackoverflow.com/questions/8638984/… 说可以,但我不能让它工作。
标签: php javascript