azam
azam

Reputation: 205

$ajax.success issue

I am retruning a string from the webmethod that is a table. The success method on the $.ajax is hit but does not insert the retruned result into the specified element.

 success: function(result){
          $('#divSubjectQuestions').html(result);
  },

when I insert some string of html then it is rendered but this code is not working.

Edit:

   int SubjectId = Convert.ToInt32(sSubjectId);
    DataTable QuestionsTable = QuestionDataAccess.RetrieveSubjectQuestion(SubjectId);

    string head = "<table class='gridstyle' cellspacing='0' rules='all' border='1'  style='border-collapse:collapse;width: 100%;'><tr class='headerclass'><th scope='col'>Subject l Questions</th></tr>";
    string body = "";
    foreach (DataRow row in QuestionsTable.Rows)
    {
        body += " <tr><td> <a  href='QuestionDisplay.aspx?Id=" + row.ItemArray.GetValue(1) + "'style='font-size:Small;text-decoration:none;'>" + row.ItemArray.GetValue(0) + "</a><br /><span  style='font-size:XX-Small;'>" + row.ItemArray.GetValue(2) + "</span>&nbsp;<span  style='color:Gray;font-size:XX-Small;'>Boosts" + row.ItemArray.GetValue(5) + "</span>&nbsp;<span  style='font-size:XX-Small;'>" + row.ItemArray.GetValue(4) + "</span>&nbsp;<span  style='font-size:XX-Small;'>" + row.ItemArray.GetValue(3) + "</span>&nbsp;<span  style='font-size:XX-Small;'>" + row.ItemArray.GetValue(6) + "</span></td></tr>";
    }
   // return head + body + "</table>";
    return "<p>boom!</b>";

Upvotes: 1

Views: 68

Answers (3)

Himanshu Jaju
Himanshu Jaju

Reputation: 1589

Might've been that you have other Ajax calls on the same page.. In that sort of case it is recommended to use different variables inside the function ... E.g. success: function(ajax1) ......

EDIT
1. Check the syntax of the function you are calling. If it is working or not. 2. Once 1. is done, put an alert("HH"); in the success function and check if you see an alert box when you do the ajax call. If no alert box can be seen then it means there is an error with the jquery code. If you see the alert box, then there is either a conflict with the jquery code or a syntax error.

Upvotes: 0

azam
azam

Reputation: 205

Actually I was returning json data so checking the result with console.log(result). I found the json object which had attached the result to "d" variable. Then accessing result.d solved the problem.

Upvotes: 1

Thierry Blais
Thierry Blais

Reputation: 2858

This is a wild guess without seeing any markup or what your data looks like but try:

 success: function(result){
          $('#divSubjectQuestions').html(result[0]);
  },

Upvotes: 0

Related Questions