Having a JavaScript function here. I am performing an AJAX call, and within the received content, there is a link that needs to trigger the JavaScript function.
MyJavascriptFunction(bla){
alert (bla);
}
Result from AJAX = "<a href="#" onclick="MyJavascriptFunction(bla)">Click</a>"
Is there anything specific that needs to be done with the result from AJAX for this to work properly or should it just work?
I have attempted the following approach but clicking the link does not produce any results:
The AJAX call:
function doSearch() {
var form = $('form');
$.ajax({
url: "doSearch.php",
type: "GET",
data: form.serialize(),
success: function(result){
document.getElementById("result").innerHTML=result;
}
});
}
In the PHP code, I am outputting:
<a href="#" onclick="MyJavascriptFunction(bla)">Click</a>