Solved

do i need to reload jquery and bootstrap js files if i submit a form via ajax?

Posted on 2014-03-01
4
1,277 Views
Last Modified: 2014-03-04
Hello

Please can you tell me if I need to reload jquery and boostrap js files if I submit a form via ajax?

I was told by one source that I do but reading here it sounds like i dont but rather have to rebind the events

http://jetlogs.org/2009/01/29/re-binding-jquery-events-on-ajax-callbacks/

However my page uses 3rd party code which contains jquery. Being as I didnt write the 3rd party code I wouldn't know what rebinding was required

Please could you explain the process that happens regarding the jquery files and ajax postbacks
0
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 250 total points
ID: 39897695
No, once its loaded on the page that's it.
If you have dynamic elements that you need to bind then you use the .on function.  This will bind any events you have programmed to dynamic/new elements

e.g.
If you wanted to capture the onclick of a dynamic anchor tag you would be writing the jquery like so

$(document).on("click",".anchor-class",function(){
...
})


This will handle existing and new elements with the class.
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39897717
Agree with Cathal.  The sequence of events in the client/server relationship is detailed in this article, which is required knowledge for web application developers.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

Upon the first request for the page, the HTML, CSS and JavaScript components are prepared by the server and sent to the client machine.  Then the server disconnects and waits.  As long as the client browser is open, the same HTML, CSS and JavaScript is in control of the client experience until it is modified by something that may have come back from an AJAX request, or any other event.  So until there is another request to reload the page, the client environment is stable.
0
 

Author Comment

by:andieje
ID: 39901398
Thanks for replies. I have read the recommended article but I still am not sure

So existing elements retain all their events associated with them?
If i add new elements and I wnat to capture their events then naturally i will have to bind to them - fair enough.

Is this correct?

Also while i'm thinking about it - though i know this is a separate question - do the stylesheets get aplied to dynamic elements created through ajax? I've not really dont ajax before. I will look this up but being a I'm here it makes sense to get a decent explanation of whats going on :)
0
 
LVL 58

Expert Comment

by:Gary
ID: 39901414
So existing elements retain all their events associated with them
Yes - unless you unbind them they keep them.
If i add new elements and I wnat to capture their events then naturally i will have to bind to them
You can either bind them when loaded through ajax or cater for them in your jQuery code to begin with by using the .on example above.

do the stylesheets get aplied to dynamic elements created through ajax
Yes
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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)

732 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