I am new to AJAX
and have stuck in a problem, I want to send AJAX CALL on button click, while button clicking the value of input field is sent to aspx.cs
(code behind) page and response should be get and I try to show that response to that same input field but it's not working.
ASPX CODE:
<input type="text" class="wpcf7-text" id="d_id" name="d_id" runat="server"> // this id is sent to the Read_Driver_Account funtion and on response it is sending the driver cell number which i want to display in the driver cell number imput field
<input class="wpcf7-text" id="driver_cell" name="driver_cell" runat="server">
<asp:Button ID="btnn1" OnClick="Read_Driver_Account" runat="server" Text="Get"/>
<script>
$("btnn1").click(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "/Udate_Driver_Account/", //Udate_Driver_Account.aspx file is placed in VisualStudio/Websites/Fp/Udate_Driver_Account.aspx, where Fp is name of my website.
data: {
id: $(this).val(),
driver_cell: $("#drivercel").val()
},
success: function (result) {
alert('ok');
},
error: function (result) {
alert('error');
}
});
});
</script>
ASPX.CS CODE:
public string drivercel;
protected void Read_Driver_Account(object sender, EventArgs e)
{
var alldata = d_id.Value;
string driveradres = tokens[7];
string drivercel = tokens[8]; // i want to set this value to the input field id="driver_cell"
}
Note: tokens[8] is a value coming from a live database it's not a static value; Also i want to set more than one values to more than one input fields.