简体   繁体   中英

Post data object using Ajax Web Api

I've tried so many samples and couldn't fix the problem. The current code is successfully posted 1st row. How to post each row in db using ajax web api?

// post marks students



     $('#btnMark').click(function () {
            var date = new Date();
            var obj = {
                "StdntId": $('#studentid').text(),
                "StdntName": $('#fullName').text(),
                "Course": $('#course').text(),
                "Date": date,
                "Status": $('#statusAtt').val()
            };
            $.ajax({
                url: '/api/Test',
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                headers: {
                    'Authorization': 'Bearer '
                        + localStorage.getItem("accessToken")
                }, 
                data: JSON.stringify(obj),
                success: function (data) {
                    $('#successModal').modal('show');
                },
                error: function (jqXHR) {
                    $('#divErrorText').text(jqXHR.responseText);
                    $('#divError').show('fade');
                }
            });
        }); 

post

If you are trying to post each row of the table then you have to iterate each row and post the data to server. The drawback of this way is you are sending a lot of request to the server. Alternatively you can iterate each row and store it as array and post all at once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM