Jump to content

Pass variable from php to javascript


wemustdesign

Recommended Posts

I have a form, I have successfully passed the username from jquery

 

$.post("cplfunctions.php?action=checkUsername", { username: username },

 

to php script. The php script checks the database to see if the username exists:

 

if ($num >=1){
	$status= '0';		
	}else{
	$status= '1';	
	}

 

 

How do I pass the variable $status back to the javascript file?

Link to comment
https://forums.phpfreaks.com/topic/204293-pass-variable-from-php-to-javascript/
Share on other sites

Given your examples:

 

cplfunctions.php

if ($num >=1) {
  $status = '0';
} else {
  $status = '1';
}
ecuo $status;

 

And the jQuery.

 

$.post(
  "cplfunctions.php?action=checkUsername",
  { username: username },
  function(d) {
    console.log(d);
  }
);

 

See http://api.jquery.com/jQuery.post/ for more details.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.