简体   繁体   English

没有输入字段的静态表格过帐

[英]Posting static form with no input fields

I am very new to web development and am confused about submitting my form data. 我对Web开发非常陌生,对提交表单数据感到困惑。 I know how to submit and retrieve data when using the tag in my html and wrapping in in a , but in this case I have a static html page displaying data in tables where the user is able to edit and modify the table input. 我知道在html中使用标记并包装到中时如何提交和检索数据,但是在这种情况下,我有一个静态html页面,用于在表中显示数据,用户可以在其中编辑和修改表输入。 How do I post the values on this form when none of the fields are of the type input? 当所有字段都不是输入类型时,如何在此表单上发布值?

You can post form data via javascript if you are generating the data on the fly. 如果您是即时生成数据,则可以通过javascript发布表单数据。 JQuery have the Ajax function that simplifies this process. jQuery具有Ajax功能,可简化此过程。 Eg, 例如,

    function post_form_data() {
        var data = {
            data1: "something,
            data2: "something else"
        };
        var url = "https://someurl.com/api/v1/etc";

        $.ajax({
            type: "POST",
            url: url,
            data: data,
            success: function() {
               // do something, like transition to 
               // a different page or something
            },
       });
    }

Call post_form_data() whenever you wish to do a post. 每当您想发表帖子时,都请致电post_form_data()。 In practice you may include the form data in function parameters or extract them from other sources. 实际上,您可以将表单数据包含在功能参数中,或从其他来源中提取它们。

To see all the detailed ajax, please read up on jQuery Ajax Documentation . 要查看所有详细的ajax,请阅读jQuery Ajax文档

On click of javascript button you can create a form and submit it: 在点击javascript按钮时,您可以创建一个表单并提交:

let form = document.createElement('form');
form.action = 'http://yourdomain/youraction';
form.method = 'POST';

form.innerHTML = '<input name="inputs" value="test">';

// the form must be in the document to submit it
document.body.append(form);

form.submit();

Instead of input value test, specify a JSON value here. 在此处指定JSON值,而不是输入值测试。

This would POST form to the provided URL. 这会将POST表单发布到提供的URL。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM