I need a script (JQUERY) that goes to another page and saves the data.

Asked

Viewed 102 times

-3

I’m sorry I didn’t show you any code because I couldn’t find a logical solution. I need a script that goes to another page and saves the data without me being on that page understand? Example: You are in index.php and have $given $dado2.

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 understand?

  • You tried using jquery json?

  • I don’t know it like it is?

  • I will formulate an example answer

  • I said Json, but it’s actually AJAX. Sleep is already beating...

  • Take a tour so you get better results in your questions. https://answall.com/help/mcve. takes advantage of this post to also https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

2 answers

2

It is not possible to "control" a page without it. Or at least not in an easy way.

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

Something like:

jQuery.ajax({
    url: 'https://www.example.com/form.php',
    type: 'POST',
    data: {
        inputUm: "Your Name",
        inputDois: "Your Message"
    }
});
  • This does not solve the problem Mr rsrs.

  • Can be a javascript..

  • I edited the answer, add the POST, before I was sending it as GET. If you can illustrate it in another way, it might be easier to understand. What I understood was that the user will be on the index.php page and you want to give possibility of him to contact without being on the contact page. Something like that.

  • I need a script that goes to another page and saves the data

  • I need a script that goes to another page and saves the data without me being there.

  • 2

    @Andressalemon When you fill out a form and submit it, an HTTP request will generally be made POST. To simulate such activity, you can manually recreate this request and send it directly to the URI that handles the form. In a way, that’s exactly what Valdeir put in the answer, although poorly explained. If this form is still in another domain, you will have to study about CORS.

  • actually I have not yet tended to the need of it. Why would you do that? Access a form of another site that you do not have direct access to? Easier to create an iframe of the site on the page that this form is.

Show 2 more comments

0

Using the AJAX of JQUERY:

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

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

Imagine 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 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 archive armazenaDados.php you recover these values:

<?php

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

.... código que armazena os dados...
  • just remembering that if the request is not for the same domain Voce may have problems with CORS depending on how the access-control-allow-origin from the other server

  • "Thank you Andrei, but my goal is to submit data not being on a page understand?";

  • @Andressalemon this data goes to a database?

  • Because maybe you’re thinking of a wrong way. Because you need to do this?

  • What do you want is to insert data in a form where you do not have access to it to be submitted automatically? Is that it? If that’s the answer... why? Maybe I can get a more viable solution.. I don’t think it’s even possible to do it the way you want it to, because the formularies are controlled by the client and not by the server.

Browser other questions tagged

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