0

How to create the confirm box (modal popup) after i click this button:

<button id="sellButton" onclick="sendRequest(@item.Id)">Sell</button>

HERE POPUP MODAL (YES/NO)

When user will confirm, then this should happen

<script>
function sendRequest(id)
{
    var request =
    {
        "itemId": id
    };
    $.ajax({
        url: '/It/Sell',
        data: JSON.stringify(request),
        type: 'POST',
        dataType: "html",
        contentType: 'application/json; charset=utf-8',
        error: function (err) {
            alert('Error: ' + err.statusText);
        },
        success: function (result) {
            $('#Table').html(result);
          },
        async: true,
        processData: false
    });
};
</script>
DiPix
  • 5,755
  • 15
  • 61
  • 108
  • Possible duplicate of [Javascript confirmation dialog on href-link?](http://stackoverflow.com/questions/10462839/javascript-confirmation-dialog-on-href-link) – rethab Jan 03 '16 at 14:29

3 Answers3

2
if(confirm('are you sure?')){
  var request =
    {
        "itemId": id
    };
    $.ajax({
        url: '/It/Sell',
        data: JSON.stringify(request),
        type: 'POST',
        dataType: "html",
        contentType: 'application/json; charset=utf-8',
        error: function (err) {
            alert('Error: ' + err.statusText);
        },
        success: function (result) {
            $('#Table').html(result);
          },
        async: true,
        processData: false
    });
}
zqcoder
  • 32
  • 3
0

Have look at jquery.confirm. It should be able to solve your problem.

casperkc
  • 81
  • 6
0

If you want to have nice modal confirm box with simple implementation i would recommend Bootstrap3 Dialog

Import necessary files to your project. And

function sendRequest(id)
   {
        BootstrapDialog.confirm('Are you sure you want to continue?', function(result){
                if(result) {
                    //Send Ajax Request
                }
            });
    }

More Info : https://nakupanda.github.io/bootstrap3-dialog/

Shanaka Rathnayaka
  • 2,462
  • 1
  • 23
  • 23