Solved

How to embed php function in javascript function.

Posted on 2011-09-06
4
408 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

820 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