Html
<input type="password" id="LoginPasswordText" title="Password" style="width: 150px" />
<input type="button" id="LoginButton1" value="Save" class="LoginButton1Class" onclick="LoginButton1OnClick" />
Json
var TextBoxData = {
Text: LoginPasswordText.GetValue(),
};
function LoginButton1OnClick() {
$.ajax({
url: "/Home/MyActionResult",
type: "POST",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(TextBoxData),
success: function (mydata) {
alert("Success");
}
});
return true;
}
MyActionResult
public ActionResult MyActionResult(string Text)
{
return view();
}
The above code snippets for Html, Json, and MyActionResult are functioning correctly with json data.
I am attempting to send the above codes as ajax data. I have tried the following code but it is not working. When I click the button, no data is sent. What could be the issue?
<script>
function LoginButton1OnClick() {
var TextBoxData = {
Text: LoginPasswordText.GetValue(),
};
$.ajax({
type: "POST",
url: "Home/MyActionResult",
data: TextBoxData,
success: function () {
alert('success');
}
});
}
</script>