Can I connect to SQL from JavaScript MVC?
- by user54197
I am populating a list of names that will be added to my Sql Database. In this simple case, how do I send the information to SQL server without my page being refreshed?
<script type="text/javascript">
function addNewRow() {
$('#displayPropertyTable tr:last').after('<tr><td style="font-size:smaller;" class="name"></td><td style="font-size:smaller;" class="address"></td></tr>');
var $tr = $('#displayPropertyTable tr:last');
var propertyCondition = $('#txtPropAddress').val();
if (propertyCondition != "") {
$tr.find('.name').text($('#txtPropName').val());
$tr.find('.address').text($('#txtPropAddress').val());
}
}
</script>
...
<table id="displayPropertyTable" width= "100%">
<tr>
<td style="font-size:smaller;" class="name"></td>
<td style="font-size:smaller;" class="address"></td>
</tr>
</table>
...
<table>
<tr>
<td><b>Name</b></td>
<td colspan="2"><input id="txtPropName" type="text" /></td>
</tr>
<tr>
<td><b>Address</b></td>
<td colspan="2"><input id="txtPropAddress" type="text" /></td>
</tr>
</table>
...
<button onclick="addNewRow();">Add</button>