Solved

Jquery - Access to the function

Posted on 2013-01-21
2
189 Views
Last Modified: 2013-02-01
Hi E's, I have this code:
$("#tela_inicial").click(function(){
em_jogo = 1;

$(function(){
        $.ajax({
        type: "POST",
        url: "abertura.php",
        data: {"nj":numero_jogo, "fase":'1', "ref":ref_puzzle, "ip":ip_cliente},
        success: function(dat){
                if(dat == ""){
                    //nao faz nada
                } else {
                // redirect
                window.location=dat;
                } 
        }
        });
});

Open in new window

That snippet code shows a function that is executed when click in the div (#tela_inicial).
My issue is, I want access to that code, but in other context.
In practice, if I click in #tela_iniciar, the script execute code inside the function.
I have a part in my code where I will need access to that code, but not with the click in #tela_iniciar.
So, my question is, how I access to that function without via #tela_iniciar?

The best regards, JC
0
Comment
Question by:Pedro Chagas
2 Comments
 
LVL 8

Accepted Solution

by:
soupBoy earned 500 total points
ID: 38801677
Try putting your 'ajax call' into its own function....then you can call it whenever you need to...

$("#tela_inicial").click(function(){
	em_jogo = 1;

	aberturaAjax();
});

$('someSelector').on('someOtherEvent', function(){
  //lets call the ajax function again!
  abertuaAjax();
});
    
function abertuaAjax(){
	$(function(){
    	$.ajax({
        	type: "POST",
            url: "abertura.php",
            data: {"nj":numero_jogo, "fase":'1', "ref":ref_puzzle, "ip":ip_cliente},
            success: function(dat){
                if(dat == ""){
                    //nao faz nada
                } else {
                    // redirect
                    window.location=dat;
                } 
          }
	});
}

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 38801755
Hi @soupBoy, what's in the box code does not matter, is just for this example, in the future can be lots of kinds of code.
What matter here, is the access to the same function, but in different way. For my case not matter what is inside the function.
It may not have solution.

~JC
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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 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)
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…

747 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

8 Experts available now in Live!

Get 1:1 Help Now