简体   繁体   中英

Dynamic Editing of form action path

I want to edit the form action url dynamically.my current code is like

    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

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

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

If using jQuery is OK, you can do it as easily as:

$.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. It just makes it easy and more readable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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