How do I get the value of a field during Ajax call?

How do I get the value of a field during Ajax call?

HillChris1234HillChris1234 Posts: 27Questions: 13Answers: 2
edited May 2016 in Free community support

I have a DataTable in .Net MVC that makes a serverSide call using Ajax. I want to pass a value to my controller based on an unrelated field on the page and then redraw the table using the ".draw()" method. However, it appears it only gets the testField value the first time the table is drawn, then won't refresh it when the "draw" method is called.

So, for this HTML element:
<input type="text" id="testField" name="testField" value="Something" />

and this DataTable setup...
var table = $('#tblBrokers').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "/Brokers/loaddata/",
"data": {
includeDeleted: $("#testField").text()
},
"type": "POST",
"datatype": "json"
},

it will pass "Something" along to the controller. But, if I change the text in the testField input, then click my checkbox that triggers a table.draw() method, it will just pass "Something" back again, and ignores what I put in the textbox. How can I make the AJAX call go back into that input to get the new value?

This discussion has been closed.