-1

I want to create a webpage, that allows user to input values, then send to 192.168.1.101:8081 via GET request.

    $(document).ready(function()
    {
        $(".sendButton").click(function()
        {
            var a = $(this).attr('value'); 
            var b = $(this).attr('value');
            $.get("http://192.168.1.101:8081/", {valueA=a}, "&" , {valueB=b});
        });
    });
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="/action_page.php">
    <fieldset>
        <legend><b><font size="4">Reference Points:</font></b></legend>
        Value A:<br>
        <input type="text" value="">
        <br>
        <legend><b><font size="4">Reference Points:</font></b></legend>
        Value B:<br>
        <input type="text" value="">
    </fieldset>
    <br>
    <br><input type="submit" class="sendButton" value=" SEND "/b>  
</form>
</body>
</html>

I know there're syntax errors. Because I know nothing about html and javascript, and only basic of php, so please excuse me.

So, when the "SEND" button is clicked, the 192.168.1.101:8081 will receive a the values from the inputs in the webpage. How? please help. Thanks

  • All i was asking was to precise your question, i don't think i am ruining the community for that. This is almost a copy/paste message that people has to say everyday, because we see so many people that don't even bother to do research. No matter what amount of research you did, it was not obvious you made any from your question. Have a good day, and don't take it personnally! – Kaddath Mar 30 '18 at 09:02

2 Answers2

2

You're in the right path.

I'd suggest you to use the submit event instead: https://api.jquery.com/submit/

Also USE AJAX, it takes care of asynchronous calls to the server.

Add an id attribute to your form and do something like this:

data: $(this).serialize() will take care of getting all the input values.

$('#you-form-id').on('submit', function (e) {
    e.preventDefault();
    var path = "http://192.168.1.101:8081/";
    $.ajax({
        url: path,
        type: "POST",
        data: $(this).serialize(),
        async: true,
        success: function (data) {
            console.log(data);
            $('div#ajax-results').html(data.output);
            location.reload();
        }
    });
});
raph
  • 68
  • 1
  • 5
  • thank you, clear explanation! And didnt know AJAX can take care of asynchronous calls. I know what to do next. Thanks again – iSeeDeadPeople Mar 30 '18 at 08:20
1

Using $_GET method:

<form name="form" action="" method="get">
  <input type="text" name="subject" id="subject" value="Car Loan">
</form>

To show the value:

<?php echo $_GET['subject']; ?>

Using $_POST method:

<form name="form" action="" method="post">
   <input type="text" name="subject" id="subject" value="Car Loan">
</form>

To show the value:

<?php echo $_POST['subject']; ?>

reference

Here is an example of passing data through URL within a site

<a href='page2.php?id=2489&user=tom'>link to page2</a>

reference 2, Passing variables with data between pages using URL

Steve Ruben
  • 1,336
  • 11
  • 20
  • I miss out putting the "method", thank you for pointing it out. And thanks for asking me to use the "echo", useful for debugging. – iSeeDeadPeople Mar 30 '18 at 08:21