【发布时间】:2016-08-11 10:27:44
【问题描述】:
我无法从 Java Script 调用 php 脚本,然后使用该结果为我的控制器设置视图包值。 下面是代码:
<script>
var model = '<% = this %>';
var data = { NAMEPARAM: model.name }
$(document).ready(function () {
$("#AlertButton").click(function () {
$.ajax({
type: 'POST',
url: "www/CustomScripts.php",
data: data
}).success(function(data) {
//need to set the returned message in view bag here.
}).error(function (data) {
alert("An error occurred while processing request")
});
});
});
</script>
<button id ="AlertButton" type="submit" class="btn green"> Alert </button>
<div id="PHPResult"> @ViewBag.message </div>
我上面面临的问题是在我的 ViewBag 中设置返回的成功消息,然后将其显示在屏幕上。我知道如何在 html div 中直接设置结果,但我需要在 Viewbag 中设置它
我将 name 参数传递给 php 脚本的方式也是如此。这是正确的方法,还是有更好的方法来实现?
【问题讨论】:
标签: javascript php jquery asp.net viewbag