Submit name value pair from javascript?

后端 未结 5 1981
鱼传尺愫
鱼传尺愫 2021-01-23 23:30

Can JS submit name/vale pairs through a document.testform.submit(); ? or does it have to be submitted through the html tags, for example



        
相关标签:
5条回答
  • 2021-01-23 23:54

    With jquery it is very simple:

    $("#formid").bind("submit", function(){
     var str = $("#formid").serialize();
     $.post("url?"+str);
     return false;
    }
    
    0 讨论(0)
  • 2021-01-23 23:54

    You could set the post data of an ajax request using only JS.

    0 讨论(0)
  • 2021-01-23 23:59

    It's plain simple using jQuery:

    $.post(url, {"name":"value"})
    
    0 讨论(0)
  • 2021-01-24 00:00

    no, you'll have to mash it yourself into JSON using javascript

    0 讨论(0)
  • 2021-01-24 00:08

    Typically you include an <input type="hidden"> in the form, and set the value you want in the event handler before it gets submitted.

    <form method="post" action="thing" id="sandwich"><fieldset>
        <input type="text" name="inputbox1" value="This is such a great form!" />
        <input type="hidden" name="jsremark" />
    </fieldset></form>
    
    <script type="text/javascript">
        document.getElementById('sandwich').onsubmit= function() {
            this.elements.jsremark.value= 'Secretly it aint that great';
            return true;
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题