使用带有ajax的post请求将html表单数据发送到php到https://foo.com

迪米特里·克鲁格里科夫(Dimitriy Kruglikov)

当用户单击按钮(以表格形式)时,将出现一个javascript提示框,询问用户名称,然后我要将javascript提示数据发送到php中,以便将其发送到phpmyadmin数据库。请注意,我已经尝试使用xmlhttprequest,但这没用,因为该网站位于https而不是http中

这是html表单:

<form method="post" id="user_form" action="Pages/Intro/Intro.php">
   <input class="button" id ="start_button" type="button"  name ="txt" onclick="loadUserName()" value="Go to Game(push Twice)">
    <br>
    <input class="button" id="help_button" name="help" type="button" onclick="location.href='Pages/Help/Help.html';" value="Help/F.A.Q" >
    <br>
  </form>

但是,我不确定如何发送此表单数据

JS(不发送至https):

function sendTextToServer(txt) {
                  var xhr = new XMLHttpRequest();
                  var formData = new FormData(myForm);
                  xhr.open("POST", "https://foo.php"); //Server goes after Post Method
                  //formData.append("txt", txt);
                  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                  xhr.addEventListener("readystatechange", function() {
                    if (xhr.readyState == 4 && xhr.status == 200) {      // state DONE, status OK
                       // your request has been received, do what you want with the result here.

                    }
                  });
                  xhr.send(formData);
                }
蓝榄

尝试使用ajax请参阅下面的示例:

var formData = $('#myForm').serialize();
$.ajax({
    url: 'https://foo.php',
    type: 'POST',
    data: formData,
    success: function(data) {
        // status code 200
        // do something
    }, 
    error: function(data) {
       // do something
    }
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从example.com/foo.php永久重定向到example.com/foo分别从example.com/foo.php到example.com/bar

PHP 发布表单未将 name="foo[]" 数据发送到 $POST 变量

元素'foo':不应使用此元素。预期为({http://www.example.com} foo)

将单词“ foo”映射到域名“ foobar.com”

使用哪个:foo和foo:

<a>标记中的http://foo.com与//foo.com?

Joomla:永久从example.com/index.php/foo/bar重定向到example.com/foo/bar(URL中没有index.php)

.htaccess 从 foo.com/sub 重定向到 bar.com/sub

如何使用脚本/别名使bash / zsh将某些文本从“ foo.foo.foo”更改为“ foo foo foo”?

我想将 example.com/chapter-foo.php 重定向到 example.com/chapter.php

我如何从'./foo'`将*导出为foo?

何时使用“导入*作为Foo”与“导入Foo”?

Clojure中的:foo,:: foo,:: bar / foo和:bar / foo有什么区别?

如何使用JAVA将数据发送到COM PORT?

如何转换List <?将Foo>扩展到List <Foo>

如何通过Ajax将表单数据和POST变量发送到php脚本

Nginx将子域foo重定向到www.foo到www.www.foo等

如何使用sed将},{“ Foo”更改为} \ n {“ Foo”?

使用params [:foo]和@foo有什么区别?

“外国进口数据Foo ::类型”与“数据Foo”之间的区别

can.routing:触发从#!/ foo / bar到#!/ foo的更改

从List <Foo>到Map <String,List <Foo >>:寻找更好的实现

将kwargs和kwargs ['foo']中的'foo'简化为True:

Swift:将Foo <String>转换为Foo <Any>

如何正确地将 _foo 转换为 `Foo` 类型?

将Map <Long,List <Foo >>转换为List <Foo>

打字稿将类型`typeof Foo`转换为`Foo`

vimperator:编写不带foo_files / *的foo.html

&foo :: function和foo :: function有什么区别?