POST form and prevent response

后端 未结 2 1740
盖世英雄少女心
盖世英雄少女心 2020-12-04 04:23

I have the following form:

On submission of thi

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 04:41

    You could just use AJAX (XMLHttpRequest in this example) to submit the post

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "http://domain.com/api.json?param=value", true);
    xmlhttp.send(null);
    

    Before hand, if you need. You can grab your param value and encode it:

    var val = encodeURIComponent(document.getElementById("param").value);
    

    then the second line would be more like:

    xmlhttp.open("POST", "http://domain.com/api.json?param="+val, true);
    

    Otherwise, any sort of submitting from a form will load a page. A hack would be to put it in a iframe thats hidden, and just delete the iframe when done.

提交回复
热议问题