Using AJAX to pass background data to the foreground JS

Source: Internet
Author: User

1, the background connection database, take the data

String sql = "..... .... ..."; ... "; ...";. ";"; ";"; ";";

String one = Oraclehelpertools.executescalar (SQL); Here's a oraclehelper.

String flow1 = Jsonconvert.tojson (one); The data is encapsulated with JSON, and the value is formatted to be parsed when it is passed into the foreground

2, in the aspx.cs of the page to write parsing

[WebMethod ()]//ajax must join

public static string Lonpoint () {

string flow = Dalflow.getflow (); Is the above code call
if (flow = = NULL)

{flow = "0"; }

var data = "{\" ng\ ":" + Flow + "}"; Add file headers required for parsing

return data;

}

3, the front desk JS to get the data and analysis

$.ajax ({

Type: "Post",

URL: "Default.aspx/latpoint",//where the above code is placed

Data: "{lat: '" + Lat + "'}",//Incoming values, no, forget it.

ContentType: "Application/json; Charset=utf-8 ",

DataType: "JSON",

Async:false,

Success:function (data1) {

var json = $.parsejson (DATA1.D); JSON parsing

$.each (JSON. NG, function (idx, item) {//ng is the file header just added

Lat.push (item[' LATITUDE '); If it is an array to write, if not then direct x= (item[' field name ');

});

},

Error:function (Err) {

}

});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.