ps. this code works on the other laptops and pc
I'm not sure how your code works on other laptops when the AJAX post is calling URL "../Home/AddAjaxE" but the action is named exrcise3_usingJqueryPost(). Are you sure you shared the correct code?
Home Controller
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult exrcise3_usingJqueryPost(string lname, string fname, string gender)
{
return Json(new { lname = lname, fname = fname, gender = gender });
}
View
@{
ViewData["Title"] = "Index";
}
<h2>Personal Information</h2>
Enter first name:
<input type="text" id="fname" />
<br />
Enter last name:
<input type="text" id="lname" />
<br />
<br />
<select id="sel_gender">
<option selected disabled> Select Gender</option>
<option value="0">Female</option>
<option value="1">Male</option>
<option value="2">LGBTQ</option>
</select>
<br />
Course
<select id="sel_course">
<option selected disabled>Select Course</option>
<option value="0">BSIT</option>
<option value="1">BSED</option>
<option value="2">BSMT</option>
</select>
<br />
<br />
Gender:<br />
<input type="radio" id="female" name="gender" value="0" />
Female
<br />
<input type="radio" id="male" name="gender" value="1" />
Male
<br />
<input type="radio" id="LGBTQ" name="gender" value="3" />
LGBTQ
<br />
<br />
<input type="button" id="btn" value="Submit" />
@section scripts{
<script>
$("#btn").click(function () {
var lastname = $("#lname").val();
var firstname = $("#fname").val();
var value = $("input[name='gender']:checked").val();
if (value == "0") {
console.log(firstname + " " + lastname + " Female");
}
else if (value == "1") {
console.log(firstname + " " + lastname + "Male");
}
else {
console.log(firstname + " " + lastname + "Other");
}
$.post('/Home/exrcise3_usingJqueryPost', {
lname: lastname,
fname: firstname,
gender: value,
}, function (data) {
console.log(data);
});
});
</script>
}
I recommend going through a few getting started tutorials to learn basic MVC programming patterns.
https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started