Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello firends,

I'm using jquery 1.6.2 in my asp.net application. every time when I'm trying to update my database using jquery.ajax() it shows me the following error.

Response:[object:object]
Status: parseerror
Text: Syntax Error: Syntax Error

This is my jquery code.
var val = $("#dpRating").val();
    $.ajax({
        type: "POST",
        url: "Media.aspx/UpdatemMethod",
        data: "{value:" + val + "}",
        contentType: "application/json",
        dataType: "json",
        success: function(data) {
            alert(data.d);
            $("#lblMsg").text("Updated");
        },
        error: function(response, status, text) {
            alert("Error \n Response:" + response + "\n Status:" + status + "\n Text:" + text);
        }
    });


Html Code
<asp:DropDownList ID="dpRating" runat="server">
  <asp:ListItem Value="0" Text="0"></asp:ListItem>
  <asp:ListItem Value="1" Text="1"></asp:ListItem>
  <asp:ListItem Value="2" Text="2"></asp:ListItem>
  <asp:ListItem Value="3" Text="3"></asp:ListItem>
  <asp:ListItem Value="4" Text="4"></asp:ListItem>
  <asp:ListItem Value="5" Text="5"></asp:ListItem>
  <asp:ListItem Value="6" Text="6"></asp:ListItem>
  <asp:ListItem Value="7" Text="7"></asp:ListItem>
  <asp:ListItem Value="8" Text="8"></asp:ListItem>
  <asp:ListItem Value="9" Text="9"></asp:ListItem>
  <asp:ListItem Value="10" Text="10"></asp:ListItem>
</asp:DropDownList>  
<input type="button" value="Submit" onclick="UpdateRating()" />


My C# Code
[System.Web.Services.WebMethod]
    public static string UpdateMethod(string value)
    {
        string res = "Entered";
        string query = string.Empty;
        if (id != null && !string.IsNullOrEmpty(area))
        {
            Media m = new Media();
            if (area == "Headers")
            {
                query = "UPDATE mytable1 SET pro='" + value + "' WHERE Id='" + id+"'";
            }
            if (area == "Contents")
            {
                query = "UPDATE mytable2 SET pro='" + value + "' WHERE id='" + id+"'";
            }
            if (!string.IsNullOrEmpty(query))
            {
                m.doQuery("",query,1);
                res = "Done";
            }
        }
        return res;
    }


Please guide me

Thanks.
Posted
Updated 21-Feb-12 1:04am
Comments
ZurdoDev 21-Feb-12 7:56am    
Is it hitting your C#? You likely need single quotes around the name and value in your data. "{'value':'" + val + "'}"
Manish Kumar Namdev 27-Feb-12 5:11am    
thanks for reply...
I have already tried this.
ZurdoDev 27-Feb-12 7:52am    
So, is it hitting your C#?

1 solution

try this

JavaScript
var val = $("#dpRating").val();
    $.ajax({
        type: "POST",
        url: "Media.aspx/UpdatemMethod",
        data: { value: val },
        contentType: "application/json",
        dataType: "json",
        success: function(data) {
            alert(data.d);
            $("#lblMsg").text("Updated");
        },
        error: function(response, status, text) {
            alert("Error \n Response:" + response + "\n Status:" + status + "\n Text:" + text);
        }
    });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900