I have this simple div:
<div id="mainContent">
</div>
and it's empty. Now I'm trying to append this HTML
to the above div:
<div id="mainContent">
<label>Project Name</label>
<input type="text" id="projectName" data-bind="value: projectName"/>
<label>Tracker Name</label>
<input type="text" id="trackerName" data-bind="value: trackerName"/>
</div>
<button type="submit" data-bind="click: submitNewProject">Submit</button>
By using:
$.ajax({
type : 'POST',
url : 'newTracker.php',
dataType : 'html',
success : function(data){
$("#mainContent").html(data);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert('Something is wrong!');
}
});
Where data
is the HTML
I'm trying to assign by: $("#mainContent").html(data);
At first look everything looks pretty, but there is a problem - the bindings are not working.
What I mean is that in the newly assigned HTML
I have a button supposed to call a viewmodel function, but it does not...
BUT if I place the code directly inside of the div the bindings are working like a charm.
Why my bidings are not working when I'm assigning a new HTML
code inside of the div? I know that I'm missing something really small and basic here, but I can't spot it.
EDIT:
Button event:
submitNewProject = function(){
console.log("submit new project");
};