我的問題是按下按鈕後缺乏動作。在按鈕下鉤AJAX功能。 請提示我有一個錯誤//錯誤。Ajax POST單擊按鈕後無法工作
我的代碼:
控制器:
[HttpPost]
public ActionResult InsertCodesToDB(string name)
{
cl.InsertCodesToDB(name);
fl.MoveCodeFileToAccept(name);
string response = "Test";
return Content(response, "application/json");
}
查看/按鈕:
<input type="button" class="btn btn-success sendCodesToDB" value="Umieść kody w bazie" data-value="@item.Name"/>
查看/腳本:
<script>
$('.sendCodesToDB').on('click', function() {
var name = $(this).data("value");
$.ajax({
url: '/ActualCodes/InsertCodesToDB',
type: 'POST',
dataType: 'json',
cache: false,
data: JSON.stringify({ 'name': 'name' }),
success: function (response) {
@(ViewBag.MessageOK) = response;
},
error: function() {
onBegin;
}
});
});
function onBegin() {
$('#files').hide();
$('#insertFiles').hide();
$('#loading').show();
$('#lblSelectedProductName').text('Trwa umieszczanie kodów w bazie danych. Proszę czekać ...');
$('#ttt').show();
}
</script>
預先感謝您的幫助。
你得到哪個錯誤?將其更改爲'JSON.stringify({'name':name}),'刪除引號。 –
是否在onBegin函數中被調用? –