Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can document.on be changed by an ajax postback

Posted on 2014-10-13
2
Medium Priority
?
419 Views
Last Modified: 2014-10-18
Hi

I was just  reading some past questions and want to make sure I understand.

Cn document.on be changed by an ajax postback e.g.

http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_28442370.html

The underlying issue is that i dont know how to correctly handle the code if an ajax request returns a form that needs validating. I validate using jquery validation module and normally just put the validation code in doc.ready

This was discussed here but many other projects have happened since then so i wanted to be sure i had understood

http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_28442370.html

thanks
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 Comments
 
LVL 34

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 40378907
greetings  andieje, , you ask - "can document.on be changed by an ajax postback ", the short answer is YES, in javascript, all variables are re-definable , as you can change or redefine most any function, since in JS functions are really treated as variables, a "named" reference to a data set or operation chain.

in any function you can define it the first time -
   $(document.body).on('click', '#MyFormSubmitButton', function(){
   alert("first definition");
    });

and then in a separate function, you can change the "on" function to do another job -
function changeOn () {
   $(document.body).on('click', '#MyFormSubmitButton', function(){
   out = $('#namer').html+" has this new";
    });
}

= = = = = = when ever you get code BACK from an Ajax call to server, it executes a function (used to be called success() ) now it should be called .done, the new and more supported name for the ajax return. When the .done function is executed, you can apply the SAME code you used in the document ready -
    jQuery(document).ready(function(){

only place it INSIDE of the .done function -
ajax.done(function( received ) {// used to be ajax.success(
  $(document.body).on('click', '#MyFormSubmitButton', function(){
      out = $('#namer').html+" has this new";
      });
  });

Open in new window


you can place other functioning code there such as validation RE-definition code to change the validation to the new form using properties from the ajax return json

However, this as all code work, requires you to know what is needed and allowed in the second validation code set, and what is NOT allowed, It may not be the identical code that the FIRST validation code used.
0
 

Author Comment

by:andieje
ID: 40388829
AWESOME
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

730 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