Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从javascript提交虚拟表单后显示相同页面_Javascript_Php_Form Submit - Fatal编程技术网

从javascript提交虚拟表单后显示相同页面

从javascript提交虚拟表单后显示相同页面,javascript,php,form-submit,Javascript,Php,Form Submit,我有这个javascript函数 function SaveData(index) { var myVirtualForm = document.createElement("form"); myVirtualForm.setAttribute('method', "post"); var name = $("#" + index + " a").attr('name'); var url = "http://localhost/my_Project/commu

我有这个javascript函数

function SaveData(index) {

    var myVirtualForm = document.createElement("form");
    myVirtualForm.setAttribute('method', "post");
    var name = $("#" + index + " a").attr('name');
    var url = "http://localhost/my_Project/communicator.php?command=save&id=" + name;
    myVirtualForm.setAttribute('action', url);

    var iframe = document.getElementById(index + "frame");
    var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
    var oTable = innerDoc.getElementById("reporttable");
    //alert(oTable.rows.item(0).cells.item(0).innerText);
    //gets table
    var str = "";
    var rowLength = oTable.rows.length;
    //gets rows of table
    for (i = 0; i < rowLength; i++) {
        //loops through rows

        var oCells = oTable.rows.item(i).cells;
        var cellLength = oCells.length;
        for (var j = 0; j < cellLength; j++) {
            var cellVal = oCells.item(j).innerText;
            var a = "";
            var b = a.concat(i.toString(), "_", j.toString());
            var obj = document.createElement("input");
            obj.setAttribute('type', "text");
            obj.setAttribute('name', b);
            obj.setAttribute('value', cellVal.toString())
            myVirtualForm.appendChild(obj);
        }
    }
    myVirtualForm.submit();
}
函数保存数据(索引){
var myVirtualForm=document.createElement(“表单”);
setAttribute('method','post');
变量名称=$(“#”+索引+“a”).attr('name');
变量url=”http://localhost/my_Project/communicator.php?command=save&id=“+姓名;
myVirtualForm.setAttribute('action',url);
var iframe=document.getElementById(索引+框架);
var innerDoc=iframe.contentDocument | | iframe.contentWindow.document;
var oTable=innerDoc.getElementById(“reporttable”);
//警报(oTable.rows.item(0.cells.item(0.innerText));
//获取表格
var str=“”;
var rowLength=oTable.rows.length;
//获取表的行
对于(i=0;i

提交后,我们转到communicator.php,但我想保持在同一页,谁不会改变。

使用ajax以虚拟表单发送数据。您真的需要创建表单吗?使用ajax,以与现在相同的方式构造所需的参数,但是使用ajax来调用php文件,但是如果您真的想使用虚拟表单,也可以使用它,这样在提交表单时不会重定向页面,只需向虚拟表单添加id属性即可