Solved

How to embed php function in javascript function.

Posted on 2011-09-06
4
401 Views
Last Modified: 2012-05-12
How to call php function in javascript function on click of html button.
0
Comment
Question by:searchsanjaysharma
  • 2
4 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36487049
0
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
ID: 36487081
You have to do this through AJAX.

With jQuery it is easy:
 
$.ajax({
		cache: false,
		url: "http://yoursite.com/yourphpfile.php, 
		type: "POST", 
		dataType: "json",
		success: function(data){
			if (data.success) {
				// your actions if successful
			} else {
				// your actions if fail
			}
		} 
   	});

Open in new window


There, in the PHP file you designate for the AJAX action you would place your call to the PHP function of your choice:
 
<?php

         $success = yourPHPFunction();
	$response = json_encode( array( 
		'success' => $success
	));
	

	header( "Content-Type: application/json" );     
	echo $response;
	exit;
?>

Open in new window

0
 

Author Closing Comment

by:searchsanjaysharma
ID: 36487094
Thanks
0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 36487113
No problem.  Best of luck to you on your project!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

863 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

20 Experts available now in Live!

Get 1:1 Help Now