简体   繁体   English

动态编辑表单动作路径

[英]Dynamic Editing of form action path

I want to edit the form action url dynamically.my current code is like 我想动态编辑表单操作URL。我当前的代码就像

    function Fbsubmit()
      {
    var cont=document.getElementById("viewcontent").value;
    var title=document.getElementById("noteheadid").value;
    var loc='http://122.98.15.171/xyx/phptest.php'+'?title='+title+'&cont='+cont;
    location.href=loc;
      }

here the problem is that user will be able to change the url while its loading the page.Can anyone suggest way to convert it as a post method 这里的问题是用户可以在加载页面时更改url。任何人都可以建议将其转换为post方法的方法

使用setAttribute()方法动态更改form method属性,如下所示:

document.getElementById("myForm").setAttribute("method", "post");

If using jQuery is OK, you can do it as easily as: 如果可以使用jQuery,则可以像以下操作一样轻松地进行操作:

$.post('http://122.98.15.171/xyx/phptest.php',
    {
        title: $('#noteheadid').val(),
        cont: $('#viewcontent').val(),
    }
);

NOTE : You don't need jQuery to do the above. 注意 :您不需要 jQuery即可完成上述操作。 It just makes it easy and more readable. 它只是使其变得容易且更具可读性。

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

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