0

The watchlistinsert.php sends some information to my database and i want it to send without leaving the original page where i clicked from. I think i need to use some ajax, I have tried a few different things, but it is not working. Hope someone can help me out.

 echo "<td>"."<a id='add' href=\"watchlistinsert.php?symbol=$symbol&price=$price&watchlistgroupid=$watchlistgroupid\">Add</a>"  ."</td>";

3 Answers3

1

You have some options at your disposal:

  1. You can - as you have already written - do it via Ajax
  2. You might be able to use WebSockets
  3. You could send an HTTP-Request to a hidden IFrame: How do you post to an iframe?
  4. You could use JavaScript to simply load an Image from your server ... and the URL said image would be the URL to your php script
Daniel Heinrich
  • 730
  • 4
  • 10
0

You can do this easily with jQuery by using the ajax() function: http://api.jquery.com/jquery.ajax/

Example:

$.ajax({
  url: "/path/to/my/file.php",
  data: {
    'key1': 'value1',
    'key2': 'value2'
  },
  success: function(data, textStatus, jqXHR) {
    // do something
  },
  error: function(jqXHR, textStatus, errorThrown) {
    // do something
  }
})

Read about all the parameters you can use at the above link.

neuromatter
  • 1,618
  • 4
  • 11
0
echo "<td>"."<a id='add' onclick=\"$.ajax({url:'watchlistinsert.php',data:{ symbol:'$symbol', price:'$price', watchlistgroupid:'$watchlistgroupid'}, success:function(response){alert('inserted!');}});\" href=\"javascript:\">Add</a>"  ."</td>";
  • Please consider adding some explanatory text, not just for the OP but also other people who come to your answer in the future with the same (or very similar) problem. – President James K. Polk Sep 14 '17 at 01:39