1

I am using asp.net and jQuery 1.6

In my function I am required to pass html tags as a data parameter to my server side method written in C#. In my Database the column has Blob datatype.
I am able to submit data successfully upto 528b but If I submit large data... I'm not able to send at server side.

When I pass small data it works and a row inserted. But If I pass data around 17Kb then this doesn't go to the sever side, but prompt me an undefined error in jquery.

Following is Ajax Code:

$.ajax({
    type: "POST",
    url: "Post.aspx/savePost",
    data: "{Title:'" + Title + "',Html:'" + Html + "'}",
    contentType: "application/json",
    dataType: "json",
    success: function (data) {
        if (data == undefined) {
            alert("Error : 219");
        }
        else {
            alert(data.d);
        }
    },
    error: function (data) {
        if (data == undefined) {
            alert("Error : 465");
        }
        else {
            alert("Error : 468 " + data.d);
        }
    }
});

Following is C# code

[System.Web.Services.WebMethod]
public static string savePost(string Title,string Html)
{
    string retMsg = "Not Saved";
    Post bp = new Post();
    int count = 0;
    count = bp.mySavePost(Title,Html);
    if (count > 0)
    {
        retMsg = "Post Save Successfully.";
    }
    return retMsg;
}

protected int mySavePost(string Title, string Html)
{
    int count=0;
    try
    {
        string rawQuery = "INSERT INTO temp_posts (Title,HTML)"
                        + " VALUES(?Title,?HTML)";
        cmd = new MySqlCommand();
        cmd.CommandText = rawQuery;
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.Parameters.Add("?Title", MySqlDbType.VarChar).Value = Title;
        cmd.Parameters.Add("?Html", MySqlDbType.Blob).Value = Html;
        count = c.insertData(cmd);
     }
     catch(Exception ex){}
 }

Please guide me with you valuable knowledge.
Thanks.

4
  • Hi, could you try to inspect the error in Firebug or Chrome Dev tools depending on which browser you normally use? It would be interesting to see whether the request is actually being sent to the server and what's the exact response. Commented Jul 23, 2012 at 11:44
  • You can use fiddler to debug your requests. Commented Jul 23, 2012 at 11:47
  • Dear Juri and Jupaol thanks to join this thread. The request is going to server when I'm passing a small amount of data. Commented Jul 23, 2012 at 11:59
  • Passing with large data request doesn't reach to server but prompt an error. I'm not able to debug. But when pass the small content then I can debug and it works successfully Commented Jul 23, 2012 at 12:19

1 Answer 1

1

Many Thanks to everyone who put his best effort for this thread.

Finally with the help of one my senior I found where I was lacking in my code.

As I am passing html tags as a data parameter to my server side method written in C# from jQuery.ajax(); I need to encode the data.

As I used the escape() function in javascript to encode it worked. Data is submitted to database.

var encodedHTML = escape(Html);         //here encoding Html.
$.ajax({  
    type: "POST",   
    url: "Post.aspx/savePost",  
    data: "{Title:'" + Title + "',Html:'" + encodedHTML + "'}",  
    contentType: "application/json",  
    dataType: "json",  
    success: function (data) {  
        if (data == undefined) {  
            alert("Error : 219");  
        }  
        else {  
            alert(data.d);  
        }  
    },  
    error: function (data) {  
        if (data == undefined) {  
            alert("Error : 465");  
        }  
        else {  
            alert("Error : 468 " + data.d);  
        }  
    }  
});  

Thanks everyone :)

Sign up to request clarification or add additional context in comments.

Comments

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.