Auswerten von Skripten in einer Ajax-Antwort
Ich habe folgenden Code:
$.ajax({
type: 'POST',
url: urlData,
data: { OwnerId: ownerIdData, Text: textData },
success: function (data) {
$('#post-container').prepend(data);
},
error: function () {
}
});
Jetzt möchte icheval
die in den variablen Daten enthaltenen Skripte in der Erfolgsfunktion. Wie mache Ich das ? Danke im Voraus.
BEARBEITEN
Ich habe folgendes Formular:
<form class="new-post-form">
<textarea id="post-creation-text-input" name="Text" rows="10"> Write something ... </textarea>
<input type="hidden" value="@Model.OwnerId" id="post-creation-id-input"/>
<input type="submit" value="Post" id="post-creation-submit-input" />
<script type="text/javascript">
$('#post-creation-submit-input').click(function (event) {
event.preventDefault();
var textData = $('#post-creation-text-input').val();
var ownerIdData = $('#post-creation-id-input').val();
var urlData = '@Url.Action("Create", "Posts")';
$.ajax({
type: 'POST',
url: urlData,
data: { OwnerId: ownerIdData, Text: textData },
success: function (data) {
$('#post-container').prepend(data);
});
},
error: function () {
}
});
});
</script>
</form>
Jetzt ist die Ajax-Antwort die folgende Ansicht:
@using Facebook.Presentation.Web.Utils
@model Facebook.Presentation.Web.ViewModels.Posts.PostViewModel
<div class="post" id ="last-post">
<h3>@Html.UserName(Model.Author)</h3>
<br/>
<div>
@Html.DisplayFor(model => model.Text)
</div>
<br/>
@{
Html.RenderPartial("_CommentsPartial", Model.Comments, new ViewDataDictionary { { "ActionName", "Comment" }, { "ControllerName", "Posts" } });
}
</div>
Diese Antwort enthält auch Skripte, die ausgewertet werden müssen.
Danke noch einmal.