I'm trying to run .ajax and insert a data element from the onClick of an item from the page. Whats the best way to do this?
Something like this:
function grabinfo(foo){
$.ajax({
url: "infospitter.php",
method: "GET",
data: "id="+foo,
success: function(html){
$(#showstuff).html(html);
}
});
}
<input onClick="javascript:grabinfo(18343)" />
// and on page each item will have this button input
This link is pretty good about explaining whay you want to do. http://elijahmanor.com/webdevdotnet/post/Embedding-HTML-from-jQuery-AJAX-Call-Into-Your-Page.aspx
Remove the "javascript:" from your onclick attribute. That's only needed when running code outside a javascript event attribute.
It's usually best to keep your javascript unobtrusive, and out of the DOM.
In your javascript file: