开发者

Why isn't this function executing?

I'm having an annoying problem which I have asked some questions about already, now I finally tracked it down, and I think I'm close to a solution, with your help of course.

I have two JavaScript files, both using jQuery, but only one of them are running. The one working starts with "$(document).ready(function() {.." and works just fine. The other one which does not work starts with "function pageLoad(){..".

The reason to why I need the pageLoad event, is because it's triggered even on async postBacks, but it's not even loaded on non-async post backs? ..

I guess there is some problem in the code which makes it bug, but it works just fine on my local machine, but as soon as it's run on my web-host's server through the Internet, everything in that javascript-file is just not working.

Code:

function pageLoad(){
    alert("this does not even show :(");
    //var's to be set
    var sendPM_pxToBottomWhenAutoScrolling = 140 //

    $(".NewConversationTrigger").click(function() {
     $("#pm_area_OpenSamtaleID").val(this.id); 
     $("#pm_area_TriggerOpenSamtale").click(); 
    });

   //Auto Scroll system for PM
   if ($(".nyPM_SubmitButton").attr("disabled") == true) {
        $(".scrollToBottom").attr({ scrollTop: $(".scrollToBottom").attr("scrollHeight") });
   }else{
        $(".scrollToBottom").animate({ scrollTop: ($(".scrollToBottom").attr("scrollHeight") - $(".scrollToBottom").height() - sendPM_pxToBottomWhenAutoScrolling) }, 1000);
   }//Auto Scroll system for PM



    //Recive开发者_JAVA技巧r PM's
   $(".SentPM:not(:last-child)").hover(function() {
    $(this).children(".PM_Options").show();
   }, function () {
    $(this).children(".PM_Options").hide();
   });//Reciver PM's
   $(".RecivedPM").hover(function() {
    $(this).children(".PM_Options").show();
   }, function () {
    $(this).children(".PM_Options").hide();
   });//Reciver PM's








    //TypeWatch
    $("#userlist_area_filterText").typeWatch({ highlight:true, callback:finished } );
        function finished(txt) { $("#userlist_area_filterSubmit").click() };

    $(".updateSamtaleVindue").click(function(){
    $("#pm_area_OpenSamtaleID").val(this.id); 
    $("#pm_area_TriggerOpenSamtale").click(); 

    });

    $(".nyPM_SubmitButton").click(function(){
    $("#pm_area_SendMessageText").val($(".nyPM_TextArea").val());
    $("#pm_area_TriggerSendMessage").click(); 
    $(".nyPM_SubmitButton").attr("disabled","disabled");  $(".nyPM_SubmitButton").val("Din Besked er Sendt"); 
    $(".nyPM_TextArea").attr("readonly", true);  $(".nyPM_TextArea").addClass("SentPM_FakeBox")

    });

    }


Since your using ASP.NET, you probably don't need to define the call to "pageLoad" with the ScriptManager. It should automatically fire with ASP.NET AJAX. There's a pretty good write up on when to use the $(document).ready() vs pageLoad(), http://encosia.com/2009/03/25/document-ready-and-pageload-are-not-the-same/.

It also mentions that you can probably move your "click" and "hover" event code over to your $(document).ready() code with the LiveQuery addition to jQuery 1.3.

It seems really odd that the $(document.ready() function would run a second time on post backs. Are you using ASP.NET AJAX? Or could you give a little more sample code from how your postback is working?


It sounds like a JavaScript error during parsing has prevented your include with pageLoad() in it from executing. Do you have any JavaScript errors in your browser when you load this page?

I noticed that you're missing a semicolon on this line:

var sendPM_pxToBottomWhenAutoScrolling = 140 //

Try correcting that and see if it makes a difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜