I have a simple PHP form like
<form action="" id="searchForm">
<input type="text" id="name" name="theName" placeholder="Your Name" />
<button id="send">Send data</button>
</form>
and I am using ajax to send the POST values to the PHP file
$("#send").on("click", function(){
var name= $('#theName').val();
var data='name='+name;
var request = $.ajax({
type: "POST",
url: "assets/map.php",
data: data,
cache: false
});
});
This works correctly when using JavaScript but I am thinking what if the JS was disabled in a browser? How we can still send the data to the server? should I add the map.php file into the form action attribute? if so how to prevent sending double POST[] values?
forms action and just prevent the default action in your JS function.