2

I have written a ajax method

if(document.URL.indexOf('LID')!=-1)
{
 $.ajax
       ({
        type: "POST",
        url: "../DL/Lecture_List.aspx/GetTitle",
        data: '{LectureID:"'+document.URL.substring(document.URL.indexOf("=")+1)+'"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: SuccessHandler
       });
       function SuccessHandler(data){
        var title = data.d;
        Add_anchor(title);
       }
}

this code is working fine in chrome but in mozilla firefox reflexing error,

ReferenceError: SuccessHandler is not defined
  • Put the function in front of the Ajax call. Realistically, you could define that inline as `function(data) { Add_anchor(data.d); }`. – pickypg May 14 '13 at 06:01
  • $.ajax ({ type: "POST", url: "../DL/Lecture_List.aspx/GetTitle", data: '{LectureID:"'+document.URL.substring(document.URL.indexOf("=")+1)+'"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (data){ var title = data.d; Add_anchor(title); } }); are you saying to write like above..? – DurGesh kuMar RAO May 14 '13 at 06:06
  • Yes. (And the `title` variable is redundant) – pickypg May 14 '13 at 06:06
  • That is working fine , but in some case i prefer to write onsuccess event as separate function (which will be easy to understand). that function is working in chorme but not in firefox, is there any mistake in declaration?? – DurGesh kuMar RAO May 14 '13 at 06:11
  • No, I do not see any mistake in your declaration. I suspect you found a bug in Firefox, which is what I was trying to see with the first setence of my first comment. You may be interested in this great [answer](http://stackoverflow.com/a/3887590/706724). Personally, it's odd to see a declaration after use, but as the answer shows, it should be syntactically valid. – pickypg May 14 '13 at 06:18

0 Answers0