Solved

jQuery working slow

Posted on 2014-09-23
6
208 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
ID: 40340866
Please share some code snippets.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40340894
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
ID: 40340923
Please share the code as its very difficult to trace the exact issue
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 82

Expert Comment

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

Author Comment

by:Sudhanshum
ID: 40341209
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
ID: 40341231
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

863 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

26 Experts available now in Live!

Get 1:1 Help Now