I have this Javascript function inside my HTML.
$("#aviso1").on('click', function (e) {
// Initialize the object, before adding data to it.
// { } is declarative shorthand for new Object()
var obj = {};
obj.titulo = $("#Titulo").val();
obj.informacion = $("#Informacion").val();
//In order to proper pass a json string, you have to use function JSON.stringfy
var jsonData = JSON.stringify(obj);
$.ajax({
url: 'Titulo.ashx?Num=1',
type: 'POST',
data: jsonData,
success: function (data) { document.getElementById("Titulo1").innerHTML = data; },
error: function (errorText) { alert("Whoops something went wrong!"); }
});
e.preventDefault();
});
But if I put it on ('click' ... if it displays the information, but when I put it on ('load' ... it does not load the information.
What is owed and how can I solve it?
EDIT: To be able to use the functions in this way so that they load automatically instead of typing
on('load' function(e) ...
or
on('click' function(e) ...
must be
ready(function(e) ...