H
H
HellCode2020-05-20 22:03:27
PHP
HellCode, 2020-05-20 22:03:27

how to pass parameter via ajax in php?

There is such a problem:

<form method="post" action="index.php?action=add&code=<?php echo $row["code"]; ?>">
<input type="text" name="price">
<input type="text" name="name">
</form>


on the side of the php handler, I accept the code (value) parameter, in ajax it turns out like this: data: $(this).serialize(), (I pull data from inputs), I need to get the code value (it is accepted as get) and at the same time pass all the data from the input via ajax

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
stdio96, 2020-05-20
@stdio96

Alternatively, you can simply add 1 hidden input and set the value to $row['code'].
In general, I don’t quite understand why send the form using the standard method if you use ajax.

A
AUser0, 2020-05-20
@AUser0

Hmm, here is POST, here is GET, and AJAX...

<form method=post action="index.php">
<input type=hidden name=action value='add'>
<input type=hidden name=code value='<?php echo $row["code"]; ?>'>
<input type=text name="price">
<input type=text name="name">
</form>

You don’t even need to change anything in AJAX, just do it in index.php instead . if ($_GET['action'] == "add")if ($_POST['action'] == "add")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question