Hi, I am trying to save data using web services, jquery and json. From some example on the web I got a similar code but I'm using a String instead of int:
HTML:
<div id="dialogL" title="Create a new Layer">
<p>Enter Name:</p>
<input id="txtValue1" type="text" size="40" />
<p>Enter Description:</p>
<textarea id="txtValue2" rows="4" cols="30"></textarea>
<br />
<input type="button" value="Create" onclick="Save()" />
JavaScript:
<script type="text/javascript">
function Save() {
$.ajax({
type: "POST",
url: "testservice1.asmx/Save",
data: "{ 'value1': " + $("#txtValue1").val() + ", 'value2': " + $("#txtValue2").val() + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: Success,
error: Error
});
}
function Success(data, status) {
}
function Error(request, status, error) {
alert("Error: " + request.statusText);
}
</script>
ASP.NET
[WebMethod]
public bool Save(String value1, String value2)
{
DoSave();
return true;
}
But this didnt work and gave me back an internal error message. What did I do wrong?
Change your data part, instead use
data: "{ value1: '" + $("#txtValue1").val() + "', value2: '" + $("#txtValue2").val() + "'}",