Why SK
posted from AJAX is undefined
and response is the html of my page?
<form class="" action="" method="post">
<form id="kod" action="" method="post">
<input placeholder="SK" name="SK" type="text" class="form-control">
<button type="button" name="submit" >Submit form </button>
<span ><?php echo $kal ?></span>
</form>
<input placeholder="HN" name="HN" type="text" class="form-control">
<button onclick="skf()"
type="submit" name="add" value="add" class="btn btn-md">ADD</button>
</form>
<!-- AJAX script -->
<script>
let skf = function(){
var SK = $('#kod input[name=SK]').val();
console.log('form:', $('#kod').html());
console.log('SK:', SK);
$.ajax({
type: 'POST',
url: 'ajaxRepair.php',
data: { SK: SK },
success: function(response){
alert("hey "+SK);
}
});
};
</script>
2
Answers
What is the reason for using two nested forms? This is not the right way to use the form
In your ajax add content type and accept.