Solved

Jquery - Access to the function

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ModalPopup  question 22 39
Getting selected value using Jquery 3 23
Making Table Thru ASP Response.write 5 21
Hide and Unhide Table 6 27
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

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