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