Call PHP Function In JavaScript Using Ajax

for this method you create three file

1. form.php
2. form.js
3. functiuon.php

1.   form.php



2. form.js

function CheckPhpFunctionInAjax()
{
var email = $(‘#email’).val();

$.ajax({
  type: ‘POST’,
  url: “function.php?f=myphpfunction&p=”+email,  // email is paramitter , if you are want to send multiple paramitter them                                                       concurrent as a string , and exploade in new page them use
  data: {},
  success: function(data1){

 alert(data1);
 if(data1==’true’){
 alert(’email already exist , please choose another email id’);
 return false ;
 }

 }});
}

3. function.php 

<?php
// include_once(‘connection.php’);

if(function_exists($_GET[‘f’])){
$_GET[‘f’]($_GET[“p”]);
}
else
{
echo “method not exist”;
}

#################################### Start Your All Function  #################################################

function myphpfunction($emailval){  // check here email avalibility into database

echo $emailval ;
/*
if(email exist into database){
echo ‘true’;
}else {
echo ‘false’ ;
}
*/
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s