PHP Include = AJAX? [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I think this will be quite a stupid question, but is the PHP include comparable to AJAX? Because I made a little page in which i load the contents via one index.php in which i have a pages array with every content page. And when I click on a link in the nav it seems to dynamically get the content, rather than reloading the page.
Can someone explain me, where the difference between AJAX and include is? Or is include in fact reloading the page rather than "swapping" contents?

is the PHP include comparable to AJAX
No.
Ajax is the process of making an HTTP request from JavaScript without leaving the current page.
A PHP include just includes some content (and may run some PHP) when the page initially loads.
And when I click on a link in the nav it seems to dynamically get the content, rather than reloading the page.
If that happens, it isn't because of an include.
The most you could get from an include is to load a complete new HTML document which has some content that is identical to the previous HTML document.
If the page loads very quickly then the user might not notice the whole page reloading, but it will still do that.

Related

How display errors in html without refreshing the form [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
this is the php code im using and want these errors(Echos) to be displayed in the html form without refreshing it after the submit button is clicked
.
THANK YOU
<?php
include 'index.php';
........
if (mysqli_num_rows($num_u) > 0 && mysqli_num_rows($num_e) > 0 ) {
echo "User Already Excist";
}
<html>
Unfortunately, changing page content without refreshing a page isn't possible in PHP. PHP runs when the page loads but once it's finished processing the only way to start the same or a new script is to make a new request. You'll have to use Javascript to execute an ajax request to populate the error.
You need to use JQuery's ajax methods.
They can get data from the server and update your dom on the fly without a page reload.
This is pretty straightforward using Get or Post
JQuery also has some other ajax methods which may be useful as well.
You can check this Create Login Form Using jQuery blog for more details, I hope it's help to you

Php opens as Text when usign "send" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
So, i've be reading a lot of post here, but as my english is not that good, i cant understand all of it.
Sorry if this has been asked here before AND ANSWERED.
My problem is that, when i launch my html file wich contains a form it opens fine... but when i click the "send" buton, it opens the post.php file as a text and doesnt launch it.
I've managed since reading your posts, that it could be a link problem and it was. If i open it from the html file, the php opens at "file:///C:/wamp64/www/Pagina/Insertar.php" (and it fails) but if i type "Localhost/Pagina/Insertar.php" it opens just fine and upload the //empty// data to my database.
What can i do to make the "send" button work? i mean, make it goes to localhost instead of file://c.
Thank you in anticipate.
( and "insertar.php" is in the same folder)
PHP scripts are only executed when loaded through a server. It sounds like you're using a relative URL for the action attribute, and loading the HTML page from a local file instead of the server. So you need to change the action to point to the server.
<form action="http://localhost/Pagina/insertar.php">

How do I send to the current page? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
In my page I have a bunch of instances where (using php) I have links sending to the same page with query strings (?action=x) so that when it sends to the same page at the beginning of the page it will see that _GET[action] isset and perform the desired action.
FOR EXAMPLE: Say you want to allow a user to delete a comment made at the end of one of their posts (on a blog). The way I learned to do it is to make the delete button a link to "currentpage.php?action=delete". Clicking the button will in a sense refresh the page where the page will see that _GET[action]=="delete" and run the code to delete the comment.
Is this the best way to do this? Is there not a way to make a click of a button cause code to run (in php) without having to refresh the page?
In addition to causing the user to lose their place in the page, there are certain cases when I won't know the actual page url and need to reference it (like if you have a "comments" function in a file that's required on each page so that you don't have to use the code to display the comments on every single page that has comments). So, I'd need a way to reference the current page in the link since I won't know it ahead of time. Is there a way to do that?
I apologize for not being clear enough earlier. Is this any better?
Take a look at the $_SERVER superglobal. It contains all the information you'll need about the current request, to reconstruct it.
echo '<pre>';
print_r($_SERVER);
echo '</pre>';

Separate php logic from html document and maintain functionality [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm having a bit of trouble wrapping my head around this problem.
I have an image map that I can click which sends various GET requests to my PHP script. My PHP script receives these GET requests and search through my MySQL Database to retrieve the appropriate information. My client is re-directed to this PHP page.
This all works and is great, but I need to incorporate Jquery for other functionality. So, I can't use a standalone PHP script.
My solution to this is use my imagemap to open up a HTML file instead, and use an include statement to incorporate my current PHP file.
However, I don't know how to include the PHP file if I need the GET requests created by clicking the image map.
How can I click on my image map, and be re-routed to a HTML page that displays the same information available from the GET requests in my PHP? I want to do this without creating multiple html files for such a small difference of one variable.
should try to use ajax-javascript to combine the php request with the javascript request and then redirect using the combined info.

Loading different parts of a web page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a webpage with a lot of youtube and soundcloud music to listen to and I was wondering what the best way would be to make it so that the music portions would not reload when certain things where clicked i.e. logging in.
Refreshing the page would start the music over again.
Ideally I would like the page to be able to play a song that would say store a small thumbnail in the corner and then the user could navigate the page freely with it still running. Kind of like how the youtube app works or, http://hypem.com
I saw someone write this bit of code, which seems pretty interesting:
<html>
<body>
<div id="projects">
<? $page = file_get_contents("projects.html"); echo $page; ?>
</div>
</body>
</html>
I'm not sure how it all works or if it is what I want so can someone point me in the right direction to achieve this?
The sample you posted will not do what you want. That will load "projects.html" and render it server-side; it will cause a full page refresh when viewed. It's not even very good code.
You basically have two options, and you've already listed one of them: Frames or ajax. Frames are the old school way of doing it and generally isn't recommended. So I recommend to go read some tutorials on Ajax/XHR to familiarize yourself with it, and then you should be able to figure out how to load chunks of content onto your page without causing a full page refresh.

Categories