Solved

jQuery working slow

Posted on 2014-09-23
6
201 Views
Last Modified: 2014-09-25
I have used JQuery in my page and added some libraries also. When i call jAlert on client side it works fine but when i call it on post back of page it takes a lot of time compared to calling it on client side.
0
Comment
Question by:Sudhanshum
6 Comments
 
LVL 1

Expert Comment

by:VijayBalkawade
Comment Utility
Please share some code snippets.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
Comment Utility
Where are you placing the script?

HTML parsing is sequential (from top to bottom) and script blocks are blocking.
This means that your code won't be parsed and executed until the HTML parser reaches there and any other scripts you might have before will delay the execution.

JavaScript is not slow and jQuery (that is nothing but JavaScript) performs very well.

Revise your code and explain us how and what exactly are you trying to do.

Cheers! :)
0
 
LVL 15

Expert Comment

by:Insoftservice
Comment Utility
Please share the code as its very difficult to trace the exact issue
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 82

Expert Comment

by:leakim971
Comment Utility
look for missing file, especially pictures.
if any, replace $(window).load by $(document).ready
0
 

Author Comment

by:Sudhanshum
Comment Utility
The code shows how i am calling the script and what jQuery files i am using.
JQUERY-Example.zip
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
Comment Utility
I don't like to do this like this.
Instead of injecting script calls, it's much clearer to have input hidden fields that define state.

Something like this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <link href="Scripts/_assets/css/jquery.alerts.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/_assets/js/jquery.js" type="text/javascript"></script>
    <script src="Scripts/_assets/js/jquery.ui.draggable.js" type="text/javascript"></script>
    <script src="Scripts/_assets/js/jquery.alerts.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            var $hasErrors = $hasErrors('#hasErrors');
            if ($hasErrors.val() === 'true') {
                jAlert("error", "message", "Error");
            }
        });
    </script>

</head>
<body>
    <input type="hidden" value="<%= HasErrors.ToString() %>" />
    
    <form id="form1" runat="server">
    <div style="width: 865px; height: 92px; margin-bottom: 0px">
        <asp:Label ID="Lbl" runat="server" Text="UserName"></asp:Label>
        <asp:TextBox ID="txtUname" runat="server" style="margin-left:10px;"></asp:TextBox>
        <br />
        <asp:Label ID="LlblPass" runat="server" Text="Password"></asp:Label>
        <asp:TextBox ID="txtPass" runat="server" style="margin-left:15px;"></asp:TextBox>
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" style="margin-left:80px;"/>
    </div>
    </form>
</body>
</html>

Open in new window

The backend should be something like (sorry if the VB code is not fully correct):
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
        'Calling the database here and validating values.
        HasErrors = True
        'Other functionalities
    End Sub

    Dim _hasErrors As Boolean = False
    Public Property HasErrors() As Boolean
        Get
            Return _hasErrors
        End Get
        Set(ByVal value As Boolean)
            _hasErrors = value
        End Set
    End Property

End Class

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now