0

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?

1 Answer 1

2

Change your data part, instead use

data: "{ value1: '" + $("#txtValue1").val() + "', value2: '" + $("#txtValue2").val() + "'}",
Sign up to request clarification or add additional context in comments.

1 Comment

Here instead of giving quotes to the arguments i have given quotes to its corresponding value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.