$ .Ajax pass a string to the background, background objects return json

var mall = {
            MallID: $("#createId").val().trim(),
            MallName: $("#createName").val().trim(),
            HomeURL: $("#chomeurl").val().trim(),
            PayNotifyURL: $("#cpayurl").val().trim(),
            RefundNotifyURL: $("#crepayurl").val().trim(),
            CompanyName: $("#createName").val().trim()
        };
        
        $.ajax({
            type: "post",
            url: "CreateMall",
            data: { mallInstitution: JSON.stringify(mall) },
            datatype: "json",
            success: function (data) {
                if (data.res == 1) {
                    alert ( "new success");
                    $("#hidenbkg").css({ "display": "none" });
                    $("#createmallshow").css({ "display": "none" });
                } else if (data.res == 0) {
                                         alert ( "MallID is:" + mallid + "business already exists, currently the largest merchant code is:" + data.Id);
                } else if (data.res == 2) {
                    alert(data.msg);
                };
            }

        });

Here is the record I am using ajax to send data to the background, do the corresponding business logic operations backstage after receiving the data; the great God is ignored, the spray would not have; if you have any good suggestions, we welcome the guidance, limited ability to express;

The above is a piece of JQuery code share with you use:

Js first build object is a mall, with the JSON.stringify (mall) converting the object into a string mall (JSON.stringfigy () method of the target sequence string js)

Then send the data back to the server using ajax (I used here is the C # MVC development model)

In using the data key value pairs ajax manner: mallInstitution: JSON.stringify (mall), so that when the server daemon interface, as long as the Request [ "mallInstitution"] can be received,

Background to the received data string, a pre-defined objects (MallInstitution) to deserialize, the corresponding data can be obtained; MallInstitution object property name must match Json target key; want you can get serializing data.

Here are some data controller receives the test code:

 1   public JsonResult CreateMall()
 2         {
 3             var test = Request["mallInstitution"];
 4             var models = new JavaScriptSerializer().Deserialize<MallInstitution>(test);
 5 
 6             //Business logic
 7 
 8 
 9             JsonResult json = new JsonResult();
10             return json;
11         }

 

Intelligent Recommendation

The pit of Ajax background interaction: background return text and string comparison problem

In a recent web project, when using Ajax to verify login information, I did not use json string to transfer information from the background for the sake of convenience, and directly used the text plai...

Ajax transfer json string background garbled???????

Title ajax pass json string background garbled Scenes: The front-end data is spliced ​​into a json string array, the Chinese in the array is not garbled before the ajax submission, and the background ...

ajax pass value to the background

Recently, a project required by the company for pre-job training was written about an e-commerce website. When the logic of the shopping cart page was achieved, there were some logical errors. Because...

JS - Pass the string of the front desk to pass the AJAX to the background - 5

Scene: Select several items in the front desk, which is batch delete (according to ID) front desk Backstage...

More Recommendation

SSM frame ajax pass parameters to the background object is acquired json

SSM frame ajax pass parameters to the background object is acquired json Front part Ajax Background controller section Front part Ajax Background controller section...

springMVC, foreground ajax pass JSON array parameters, how to receive background

Background sections: // json package used: com.alibaba.fastjson...

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

Use Ajax to pass the JSON array to MVC background front end Front -end code: Background code:...

Postman json request parameters to pass objects and arrays to the JAVA background

1. The entity class object is passed in JSON format, and the postman request parameter format is as follows (Headers request header to add Content-Type: application/json) The background reception is a...

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

Top