Jump to content

Recommended Posts

I’m not sure if this is a php or javascript question. I changed my yesterdays query to hopefully clarify what I am asking.

I have a little program “getFileDate.php”

<?php

function getFileDate ($filename) {

    return date ("F d Y H:i:s.", filemtime($filename));

}

?>

 

Is it possible to call this from javascript and pass a file name to it, then receive the date back?

 

Bob

 

Link to comment
https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/
Share on other sites

Would someone explain AJAX to me? How do I know if I have it? I used jquery.js somewhere. Does that make it AJAX? I guess my question is how do I install it?

 

Bob

 

There are plenty of tutorials and information online.  JQuery is a nice framework and one of the most popular to work with AJAX.

Well I would think you can get javascript variables to php by loading a php file with query strings, Set by php. Or using a form.

 

Not sure what you mean exactly.

 

Because I'm an idiot  :-\. Let me rephrase:

 

"I would think you could post javascript variables to php using query strings, Or you could post javascript variable to PHP through a form"

 

But then you would have to load a complete new page. In some cases this wouldn't be a problem but It's alot easier to get PHP into javascript. <?=$variable?>

I'm having a real challenge with this. Would you give me an example using <?=$variable?>? I just don't see how this would communicate with a php routine. I have this little test routine

http://www.treeful.com/temp/phpFile.php?param1=test

but have no idea how to get its result back to javascript. And not sure how to pass param1 to it.

Is this possible?

 

Bob

PS the php I would like to use is

<?php

function getFileDate ($filename) {

if (file_exists($filename)) {

    return date ("F d Y H:i:s.", filemtime($filename));

}

}

?>

Well I would think you can get javascript variables to php by loading a php file with query strings, Set by php. Or using a form.

 

Not sure what you mean exactly.

 

Because I'm an idiot  :-\. Let me rephrase:

 

"I would think you could post javascript variables to php using query strings, Or you could post javascript variable to PHP through a form"

 

But then you would have to load a complete new page. In some cases this wouldn't be a problem but It's alot easier to get PHP into javascript. =$variable?>

 

Sure, if you reload the page you can pass values to PHP via HTTP.  If you don't want to reload the page you have to use AJAX.

I'm really feeling like an idiot now. I seem to be going in circle. What does a web site need to use AJAX. I have a test program

http://www.treeful.com/temp/phptest.php. Is this AJAX?

_____________________________________

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>call php test</title>

<script type='text/javascript' src='jquery.js'></script>

<script type='text/javascript'>

function testing() {

$.get(

  'phpFile.php',

  {

'param1' : 'value'

  },

  function(response) {

  }

);

}

</script>

</head>

<body onLoad="testing()">

</body>

</html>

_____________________________________________________________

This does not call the file 'phpFile.php'. (At least it does not echo anything)  Would reloading page help? & if so where would I do it?

 

Bob

There was a period added to end

http://www.treeful.com/temp/phptest.php/

You can always just go to the directory to see my feeble attempts

http://www.treeful.com/temp/

I went to your link but it's too complicated for me. I work best from examples.

I think I'll give the whole idea up for the time being.

Thanks for your help.

Bob

 

There was a period added to end

http://www.treeful.com/temp/phptest.php/

You can always just go to the directory to see my feeble attempts

http://www.treeful.com/temp/

I went to your link but it's too complicated for me. I work best from examples.

I think I'll give the whole idea up for the time being.

Thanks for your help.

Bob

 

 

I cannot view your source.  The jquery link I gave you should provide many examples.  Try and implement one and come back with your source for specific help.  There are also many examples on this site for AJAX using jQuery.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.