Execute php file with javascript [closed]

1

Hello I need to run a php page, I just want to send the par par that I can do a basic function but I'm not doing this with javascript.

<script type="text/javascript"> 

function removemen(id){ 

load('functions/atumensainbox.php?id_del=' + id );

}; 

</script>
<div class="title" onclick="passar(2);" ><b>Pasando id por click</b></div>


Pego o id e executo uma função depois pelo por _REQUEST
<?php

$id_dels=$_REQUEST['id_del'];

?>

Thank you in advance

    
asked by anonymous 03.09.2016 / 20:48

1 answer

3

Why is not it working?

In the snippet where you are using load(url) , I imagine you expect it to access the url you provided, and when the execution gets there you finish solving things. However, load(...) in your code causes javascript to understand that there is a function called load , such as function load(url){...} created or imported by you at some point. At jQuery the correct would be to use the $.load() [+] function assigned to some element in its HTML , for example: $("body").load(url) . See here the statement is different from the way you tried on your first attempt.

Here is the solution

The jQuery provides the $.get function [+] and $.post [+] , which are no more than shortcuts to $.ajax(...) [+] which allows you to execute access to a url by its javascript code. This function is unique to jQuery , which can be downloaded by here .

If you test, you will see that $.load works equal $.get . The jQuery documentation explains how to use both forms. $.load is assigned to some element in the structure that will receive the execution response of url , $.get will depend on you will want to handle the execution response of url .

The implementation in your code will be:

<script type="text/javascript"> 
function removemen(id)
{
    var url = 'functions/atumensainbox.php?id_del=' + id;
    $.get(url, function(retorno){
        /* aqui o tratamento de alguma retorno que o final da execução da sua url fornece*/
    });
}; 
</script>

If there is no return on the execution of your url , the , function(retorno){} does not need to be issued.

    
03.09.2016 / 22:16