I need a script (JQUERY) to go to another page and save the data. [closed]

-3

Sorry for not showing any code, because I did not find a logical solution. I need a script that access another page and save the data without being on that page understand? Example: You are in index.php and have $ given $ given2.

Now the mission is: Send this data to the other page, save the data in the submit of another page. All this without being present on the other page do you understand?

    
asked by anonymous 19.12.2017 / 05:18

2 answers

2

You can not "control" a page without it. Or at least not easily.

Depending on what you really want, it would be best to use jQuery.ajax to make this request on the index.php

Something like:

jQuery.ajax({
    url: 'https://www.example.com/form.php',
    type: 'POST',
    data: {
        inputUm: "Your Name",
        inputDois: "Your Message"
    }
});
    
19.12.2017 / 04:42
0

Using AJAX of JQUERY :

First of all you need the JQUERY library linked in your script like this:

<script src='jquery.js' type='text/javascript'></script>

Imagine that you have this form in your index.php :

    <form>

        <input id="dado1" type="text">
        <input id="dado2" type="text">
        <input id="enviar" type="submit">

    </form>

When you click submit, ajax will send the input values to the page armazenaDados.php

   <script>
    $('#enviar').on('click',function(){ 

        var dado1 = $('#dado1').val();
        var dado2 = $('#dado2').val();

        $.ajax({ 
            url: 'armazenaDados.php', 
            type: 'POST', 
            data: { dadoA: dado1, dadoB: dado2 },
            success: function(data) { 
               alert("alterado!"); 
            } 
        }); 

    });
</script>

In the file armazenaDados.php you get these values:

<?php

$dado1 = $_POST['dadoA'];
$dado2 = $_POST['dadoB'];

.... código que armazena os dados...
    
19.12.2017 / 05:46