Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

AJAX call to return success or fail

$
0
0

I have a button which calls a function onClick and passes a couple of parameters. I need to use AJAX to pass these two parameters to the controller and onsuccess do something client-side. Here's the button and the ajax call:

<button type="button" class="btn btn-default" onclick="addComponent(@item.ID, @item.VendorID)">Add</button>
function addComponent(componentId, vendorId) {
$.ajax({ type: 'POST', url: '@Url.Action("WriteSupportComponent")', contentType: false, dataType: 'json', data: { "componentId": componentId, "vendorId": vendorId }, success: function (response) { console.log('returned success');$('#' + componentId).remove(); console.log('removed tr'); }, error: function (ex) { console.log('returned failed: ' + ex.responseText); } });
}

How do I need to structure the controller to do something (write to db in this case) and then return success or failed back to the function?

Thanks in advance
Adam


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>