Use Ajax to pass the JSON array to MVC background front end

tags: front end  mvc  ajax

Use Ajax to pass the JSON array to MVC background front end

Front -end code:

$.ajax({
    async: false,
    url: '/controller/action',
    data: JSON.stringify({ hand: newjsonObjIte, logsql: log }),
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    type: 'post',
    success: function (data) {
        // Back results
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        layer.msg("Error:" + textStatus + '-' + XMLHttpRequest.statusText + '-' + XMLHttpRequest.responseText);
    }
});

Background code:

/// <summary>
/// Batch newly added
/// </summary>
/// <param name="hand"></param>
/// <param name="logsql"></param>
/// <returns></returns>
public ActionResult action(List<sn_bd_hand> hand, string logsql = "")
{
    string sError = "";
    if (!string.IsNullOrEmpty(logsql))
        logsql = CreateLogsql(logsql);
    int res = snMainBLL.PlAddHand(hand, logsql, ref sError);
    return Json(new { successed = res, msg = sError });
}

Intelligent Recommendation

[Front end] Use JQuery and AJAX to transfer Table data to the back end in the form of a JSON array

Use JQuery and AJAX to transfer Table data to the backend in the form of a JSON array...

Spring boot front pass JSON array, background reception processing

  Defined entity class: JSON data format passing at the front end Back end interface:  ...

About Ajax front-end Json data acceptance and background data analysis

About Ajax front-end Json data acceptance and background data analysis Specific issues Method analysis 1. Do not add the contentType attribute Add contentType: "application/json" attribute t...

SpringBoot front-end Ajax obtains background data in JSON format

I'm doing a project with Thymeleaf recently. I always hear the words of separation of front and back ends. I have to learn about how to get the back-end json string in Thymeleaf. Here is a detailed ex...

More Recommendation

Front end --- AJAX and JSON

One, AJAX Concept: Asynchronous JavaScript and XMl ① Asynchronous and synchronous: based on the communication between client and server Synchronization: The client must wait for the response from the ...

Beginning AJAX, use PHP to pass PHP to the background database with the front desk

I have recently been studying this course. The course is busy. I used the time under or before going to bed to learn AJAX to pass the value. Let ’s show you a very simple model box message board...

Front end ajax pass array, backend spring accept

ajax spring the key code is @RequestParam(value=“overtimeids[]”)!!!...

Use AJAX to pass JSON, return to the front desk Chinese garbled problem

First look at the status before solving:   The framework I use is SSM. In SpringMVC, I configured the encoding format as UTF-8. Each JSP page also used UTF-8. When it was submitted to the backgro...

ajax pass array to python background

Purpose: pass [1,2,3,4] such an array to the background I was struggling with this issue for a while, the first was to use the json string Later found request.args.getlist() This mentality collapsed. ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top