How to insert .php page inside an HTML element with JS

1
Hello, I'm calling a page .php with method load , its problem is that when I give include to something it should be include './dir/arquivo.php'; after load loads the page % is forced to stay this way to work include , plus some elements do not work.

But when I use only ../dir/arquivo.php direct, without JS to call, it works perfectly, I'd like a way to make JS (or even PHP) run include ( or some form that is not include 'arquivo.php' ) when the button is pressed.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script><scriptsrc="http://malsup.github.com/jquery.form.js"></script> 
<script type="text/javascript">   
$(document).ready(function(){
    $("#button").click(function(){
        $("#div").load('arquivo.php');
    });
});
</script>
<input type="button" id="button">
<div id="div"></div>

Sample code that does not work:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script><scripttype="text/javascript">   
$(function() 
{
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');

var upload = $('form').ajaxForm(
{
    beforeSend: function() 
    {
    },
    uploadProgress: function(event, position, total, percentComplete) 
    {
        //aumenta barra de progresso
    },
    complete: function(xhr) 
    {
    }
});
});
</script>

<form enctype="multipart/form-data" method="post" id="formSendTorrent"    name="formSendTorrent">
    <input type="file" multiple name="inputfileSendTorrent[]"       id="inputfileSendTorrent"> 
    <input type="submit" name="submitSendTorrent" value="Enviar">
</form>
<?php 
if(isset($_POST['submitSendTorrent']))
{      
header('Location: index.php');
} 
?>
    
asked by anonymous 11.03.2017 / 16:21

1 answer

1

It is not possible to include a php file inside the javascript, because it works on the local machine of the user, while php works on the server, which is interpreted and sent to the browser in html format.

One solution to your problem is to use ajax. Ajax can send information to php running on the server without reloading the screen, making it possible to perform functions that would not be possible locally.

Take a look at this article explaining the basics about it: link

  

AJAX is a developer's dream, because you can:

     

• Update the web page without reloading the page Request data from a server   • after the page has loaded   • after the page has been loaded Send the date to a server - in the background

Ajax is the dream of developers because you can: Refresh a page without reloading it with server data. Receive data after page loading. Send data in the background after page loading.

    
14.03.2017 / 14:13