Solved

How to embed php function in javascript function.

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

831 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