Doubt about ajax (javascript)

Asked

Viewed 22 times

-2

to with a doubt, have to send from index to api (using ajax) more than one value?. I am accused of using the code like this. But I don’t know how to send the value of 2 different inputs.

<script>
$.ajax({
    url: 'api.php?line=' + value,
    type: 'GET',
</script>
  • I didn’t understand your doubt, try to explain it more clearly so you can be helped.

2 answers

0

Use & to separate the parameters:

$.ajax({
    url: 'api.php?line=' + value + '&other=' + outro,
    type: 'GET'
});

If many values, or long values, use POST instead of GET.

0

I advise to research about query strings is that actually its limitation and that has nothing to do with the request via Ajax.

See an article on query string in Wikipedia https://en.wikipedia.org/wiki/Query_string

Do not enter details about constructing the URL to indicate that the parameters in the URL are separated by the "&" character according to the formula: name_do_parametro_1=value_do_parametro_1&name_do_parametro_2=value_do_parametro_2&name_do_parametro_3=value_do_parametro_3...

Using your example I will add column parameter

<script>
$.ajax({
   url: 'api.php?line=' + value +'&coluna=' + value2,
   type: 'GET',
</script>

Browser other questions tagged

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