How do I get the JSON.parse to be evaluated in and AJAX function because TextBox5-9 are empty.
This should work.
I have returning data for both differences instances from the WebMethod function getDate.
$("#<%= TextBox4.ClientID %>").val(result.d);
prints out either of the two JSON data below and is working.
"[{id:1, datetime:04/10/2017, col1:1, col2:2, col3:2}]"
and
"{\"id\":1,\"datetime\":04/10/2017,\"col1\":1,\"col2\":2,\"col3\":2}]"
TextBox5-9 are not giving any data like they should. The JSON class structure is not being read.
This should work.
<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#<%= Button1.ClientID %>").click(function () {
var mo1 = $("#<%= TextBox1.ClientID %>").val();
var dy1 = $("#<%= TextBox2.ClientID %>").val();
var yr1 = $("#<%= TextBox3.ClientID %>").val();
var data = { mo:mo1, dy:dy1, yr:yr1 };
var json1 = JSON.stringify(data);
$.ajax
({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: json1,
url: "Default.aspx/GetDate",
success: function (result) {
$("#<%= TextBox4.ClientID %>").val(result.d);
var datereturn = JSON.parse(result.d);
$("#<%= TextBox5.ClientID %>").val(datereturn.id);
$("#<%= TextBox6.ClientID %>").val(datereturn.datetime);
$("#<%= TextBox7.ClientID %>").val(datereturn.col1);
$("#<%= TextBox8.ClientID %>").val(datereturn.col2);
$("#<%= TextBox9.ClientID %>").val(datereturn.col3);
},
error: function (status, ex) {
alert("Error Code: Status: " + status + " Ex: " + ex);
}
});
return false;
});
});
</script>
What I have tried:
I have tried many returning formats of the JSON returning from the WebMethod GetDate. Like I said this produces one of the two JSONs in TextBox4 in correct form. It just does nt print out the Json Classes. I have tried "return" instead of "return.d".