Solved

Jquery - Access to the function

Posted on 2013-01-21
2
192 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Show "please wait " message as page loads 2 42
How do specify keydowns in JavaScript 3 46
Javascript_Set_dropdown_value 7 33
Javascript Form Change 5 23
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

809 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