-3

There is a URL (wrapped in a-tag) in my html page. How can I send some additional data (it is can be change dynamically by a client (inputs)) to the server when my user making a GET-request (for example, as parameters of the URL). I can't use html-form, I just should do it as URL.

I try to explain clearer. URL is just a link to the content. However my server need some additional data for child action. It were entered by user (some entry fileds - for example a string of the search)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mergasov
  • 31
  • 5

2 Answers2

0

This will use ajax to call your server on mydomain.com, and a php script called server.php. It will pass a single parameter called url, and it will equal whatever is in the address bar.

If successful, and if the server responds with anything, it will be written to the console log

$.ajax( {   
    "data": "/server.php?url="+encodeURIComponent(window.location.href.toString()) ,
    "success": function(data)
             {   console.log(data); }
});

Extra info on getting the URL: Get current URL in web browser

Community
  • 1
  • 1
0

You can do some like that:

HTML:

<a href='http://www.google.com' id='myLink' data-url='http://www.google.com/' />

JS:

var src = $('#myLink')[0].getAttribute('data-url');
$('#myLink')[0].href = src + "?myNewParameter=myValue";

I hope this helps :D

Fabricio
  • 3,248
  • 2
  • 16
  • 22