Erodov.com Forums | India's Top Technology forum.
Loading

navigation
  • Home
  • Forums
  • Articles
  • News
  • Gaming
  • Bazaar
  • Community
  • What's New
  • My Erodov
  • Help
navigation
Go Back   Erodov.com Forums | India's Top Technology forum. > Software Zone > Programming
Register Forgot Password?

 
 
Thread Tools Search this Thread
Old 04-05-16   #1
teh nuB!
I havent set my status yet.
 
 
europeanoverse's Avatar

How Can You Use Php in a Javascript Function


How can you use php in a javascript function



Singapore Tourist Visa Consultants Ludhiana, Punjab, India
europeanoverse is offline   Reply With Quote
Old 22-10-16   #2
teh nuB!
[E]onian
I havent set my status yet.
 
 
xman0752's Avatar

 
Join Date: Oct 2016
Location: kolkata
Posts: 69
xman0752 is Mysterious
Re: How Can You Use Php in a Javascript Function

You can't run PHP code with Javascript. When the user recieves the page, the server will have evaluated and run all PHP code, and taken it out. So for example, this will work:

alert( <?php echo "\"Hello\""; ?> );
Because server will have evaluated it to this:

alert("Hello");
However, you can't perform any operations in PHP with it.

This:

function Inc()
{
<?php
$num = 2;
echo $num;
?>
}
Will simply have been evaluated to this:

function Inc()
{
2
}
If you wan't to call a PHP script, you'll have to call a different page which returns a value from a set of parameters.

This, for example, will work:

script.php

$num = $_POST["num"];
echo $num * 2;
Javascript(jQuery) (on another page):

$.post('script.php', { num: 5 }, function(result) {
alert(result);
});
This should alert 10.

xman0752 is offline   Reply With Quote
Old 15-06-17   #3
teh nuB!
I havent set my status yet.
 
 
umaga's Avatar

 
Join Date: May 2017
Posts: 2
umaga is Mysterious
Re: How Can You Use Php in a Javascript Function

No, you cannot run php codes in javascript. Because both of them are different languages. So, you cannot use each other's code in one another. So, if you need anything in php that is available in javascript you can use different codes.

______________________
static code analyzer
umaga is offline   Reply With Quote
Post New Thread  Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Like This Post Function tpi Feedback and Test Drive 0 20-05-12 09:23 AM
Critical JavaScript vulnerability in Firefox 3.5 vijayninel Interesting News on the Web 5 19-07-09 07:26 AM
Cnet: Chrome's JavaScript challenge to Silverlight Mav3ricK Applications 0 08-09-08 09:55 AM
Firefox 3.1 whips Chrome in SunSpider JavaScript benchmark Mav3ricK Applications 1 07-09-08 04:05 AM
New Firefox JavaScript engine is faster than Chrome's V8 gamer Applications 2 05-09-08 11:48 AM


Tags
agents, function, javascript, php, singapore, tourist, visa
All times are GMT +5.5. The time now is 03:08 AM.
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 PL2 ©2011, Crawlability, Inc.