无需离开原始页面即可发送数据

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>";

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.

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
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>";