Run php file with javascript

Asked

Viewed 80 times

1

Hello I need to run a php page, I just want to send the id to execute a basic function but n I am therefore 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'];

?>

from now on

  • 1

    Barter load(...) for $.get(...).

  • 1

    Thanks friend had forgotten the get remembered that the load was for me to take something from the page and print on another Valew same thank you etc

  • It was a pleasure to help, Gezer! @Anthonyaccioly, posted a more elaborate reply. Thank you ;)

1 answer

3


Why isn’t it working?

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

That is the solution

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

If you test it, you’ll see $.load works like the $.get. The documentation of jQuery explains how to use the two forms. $.load is assigned to some element in the structure that will receive the response of the url, $.get will depend on with you will want to deal with the response of the execution 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 from the execution of your url, the stretch , function(retorno){} does not need to be issued.

  • William, I found it very explanatory clarified me well , now I got a doubt (I’m beginner of js) : The function "load()", is then a method exclusive to Jq, and in pure js it would be identical to a function "Function abra()", that part I’m confused ?

  • @Magichat yes, you are right about the functions on javascript :) As to the jQuery I edited the answer for better understanding.

  • 1

    very good thanks friend for the tip and great explanation. Best answer. I am beginner also rsrs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.