Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Jquery - Access to the function

Posted on 2013-01-21
2
Medium Priority
?
199 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
[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 8

Accepted Solution

by:
soupBoy earned 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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.
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

610 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