Jump to content
iwato

Inserting PHP in an HTML Insert Has Not Yet Been Inserted

Recommended Posts

BACKGROUND:  I have a plain text file with an .html extension.  In the file is a <p> element into which I would like to enter the current date. The file is called from its hostpage via a jQuery $.get() statement that is followed with an AJAX call to a PHP processing file that returns JSON that can be processed in the AJAX success function as an object.

QUESTION:  If I place the PHP necessary to create the date in the text file with the .html extension, will it appear in the hostpage when called by the $.get() method?

NOTE:  My server is programmed to accept PHP in files with a .html extension.  Mind you, the text file has neither <head>, nor <body> element, let alone a <DOC> header.

Roddy

 

 

 

If I enter the data with PHP before the AJAX

Share this post


Link to post
Share on other sites

If I place the PHP necessary to create the date in the text file with the .html extension, will it appear in the hostpage when called by the $.get() method?

Is your server configured to send .html files to PHP?  If so, then yes.  If not, then no.

Share this post


Link to post
Share on other sites

It is configured, but the file in question does not respond as hoped.

<?php echo date("r"); ?>

Roddy

Share this post


Link to post
Share on other sites

And how exactly does it respond?

The basics are pretty simple: if the web server receives a request for a certain URL, and it has been configured to handle that URL with PHP, then it will.  If it's not, then one of the assumptions you've made is not correct.  Maybe it's not configured correctly, maybe there's an .htaccess file telling it to do something else, etc.

Share this post


Link to post
Share on other sites

Recently my hostserver modified their system and notified me of an .htaccess file that they placed on my website so that my HTML files could handle PHP.  I opened and examined it, but saw nothing out of the ordinary.  In fact, it appears very similar to what I use to use on my own test server before my hard disk failure.  The file's permissions are 644.  Might the problem be related to the absence of header tags?  Once again, the file is little more than a text file with an .html extension.  The document begins and ends with the same <div> element.

Roddy

Share this post


Link to post
Share on other sites

By changing the file's extension from .html to .php and then using the $.get() method to call it in its modified format the problem was resolved.  Unfortunately, I am still confused as to why this modification was necessary, when I have other files with the HTML extension that have no trouble processing PHP.

Roddy

Share this post


Link to post
Share on other sites

If that is controlled by .htaccess then it's dependent on the location of that file.  Files in different directories may behave differently if the rules in .htaccess say that.

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×