js 模仿post传输数据

function sub($id)
    {
        var nnme = $('#a'+$id).attr('nnme');
        var location = $('#a'+$id).attr('location');
        var address = $('#a'+$id).attr('address');
        
        //调用下面的方法,参数1 地址 ; 参数2 input的name input的value
        post('index.php', {nnme:nnme,location:location,address:address})
    }
        
        


    function post(URL, PARAMS) {
      var temp = document.createElement("form");
      temp.action = URL;
      temp.method = "post";
      // temp.style.display = "none";
      for (var x in PARAMS) {
        var opt = document.createElement("textarea");
        opt.name = x;
        opt.value = PARAMS[x];
        // alert(opt.name)
        temp.appendChild(opt);
      }
      document.body.appendChild(temp);
      temp.submit();
      return temp;
    } 

猜你喜欢

转载自blog.csdn.net/tingmmdh/article/details/81032359