JSON data parsing

Source: Internet
Author: User

function Createxmlhttp () {

if (typeof XMLHttpRequest! = "undefined") {
return new XMLHttpRequest ();
}
else if (window. ActiveXObject) {
var aversions = ["msxml2.xmlhttp.5.0", "msxml2.xmlhttp.4.0", "msxml2.xmlhttp.3.0", "Msxml2.xmlhttp", " Microsoft.XMLHTTP "];
for (var i = 0; i < aversions.lenght; i++) {
try {
var oxmlhttp = new ActiveXObject (aversions[i]);
return oxmlhttp;
}
catch (Oerror) {

}
}
}

throw new Error ("XMLHttp object could be created.");
}
Contentplaceholder1_drpcity Contentplaceholder1_drpcounty


Function Getxml (m) {
var thisid = "";
  if (m = = 1) {
Thisid = "#ContentPlaceHolder1_drpCity";
  
Else if (m = = 0) {
Thisid = "#ContentPlaceHolder1_drpProvince";
}
var parentid = $ (thisid). Val ();
var oxmlhppt = Createxmlhttp ();
var url = "jsonprovincedata.aspx?parentid=" + parentid;
Oxmlhppt.open ("Get", url, True);
Oxmlhppt.onreadystatechange = function () {
if (oxmlhppt.readystate = = 4)//Xmlhttp.readystate = = 4 response completed; You can obtain and use the server's response to the
{
if (oxmlhppt.status = =)//xmlhttprequest object's Status property, which is typically used to return the HTTP status code of the server. A status of 200 means "success"
{
//alert (oxmlhppt.responsetext);

Getjsondata (Oxmlhppt.responsetext, M); Oxmlhppt.responsexml get the XML document
}
}
}
Oxmlhppt.send (NULL);
}
$ (document). Ready (function () {
$ (' #ContentPlaceHolder1_drpProvince '). Change (function () {
$ (' #ContentPlaceHolder1_drpCity '). empty ();
$ (' #ContentPlaceHolder1_drpCity '). Append ("<option value= '-1 ' > Please select City </option>");
$ (' #ContentPlaceHolder1_drpCounty '). empty ();
$ (' #ContentPlaceHolder1_drpCounty '). Append ("<option value= '-1 ' > Please select County </option>");
Getxml (0);
});
});
$ (document). Ready (function () {
$ (' #ContentPlaceHolder1_drpCity '). Change (function () {

Getxml (1);
});
});

function Getjsondata (data, m) {
var Sjson = eval ("(" + Data + ")");
if (M = = 0) {
$ (' #ContentPlaceHolder1_drpCity '). empty ();
<option value= "-1" > Please select City </option><option value= "313" > Baiyin </option>
$ (' #ContentPlaceHolder1_drpCity '). Append ("<option value= '-1 ' > Please select City </option>")
for (var i = 0; i < sjson.length; i++) {
$ (' #ContentPlaceHolder1_drpCity '). Append ("<option value=" + sjson[i]. Codeid + ">" + sjson[i]. CityName + "</option>");
}
}
else if (m = = 1) {
$ (' #ContentPlaceHolder1_drpCounty '). empty ();
$ (' #ContentPlaceHolder1_drpCounty '). Append ("<option value= '-1 ' > Please select County </option>");
for (var i = 0; i < sjson.length; i++) {
$ (' #ContentPlaceHolder1_drpCounty '). Append ("<option value=" + sjson[i]. Codeid + ">" + sjson[i]. CityName + "</option>");
}
}

}
Shipping Address
function Getconsigneeinfo () {
var oXmlHppt1 = Createxmlhttp ();
var url = "jsonconsigneeinfo.aspx?cj=" + math.random ();
Oxmlhppt1.open ("Get", url, false);
Oxmlhppt1.onreadystatechange = function () {
if (oxmlhppt1.readystate = = 4)//xmlhttp.readystate = 4 response completed; You can get and use the server's response
{
The Status property of the IF (oxmlhppt1.status = =)//xmlhttprequest object is generally used to return the HTTP status code of the server. Status of 200 means "success"
{
alert (Oxmlhppt1.responsetext);
Getjsondataconsignee (Oxmlhppt1.responsetext); Oxmlhppt.responsexml get the XML document
}
}
}
Oxmlhppt1.send (NULL);
}
function Getjsondataconsignee (dataobj) {
var Sjson = eval ("(" + Dataobj + ")");
alert (sjson.length);
$ ('. Myaddrlist '). empty ();
for (var j = 0; J < Sjson.length; J + +) {
if (Sjson[j]. Isdefault = = "1") {
$ ('. Myaddrlist '). Append ("<li class= ' curr ' onclick= ' Selectedli (this) ' onmouseover= ' selectedlihover (This) ' Onmouseout= ' Selectedliout (this) ' > <p class= ' address-name ' > <strong> "+ sjson[j]. Consigneeaddressname + "</strong> <span class= ' address-close ' onclick= ' Deleteconsignee (this) ' > delete </ span> <a class= ' address-edit ' onclick= ' Editconsignee (this) ' >[modify]</a> <input type= ' hidden ' value= ' " + Sjson[j]. Consigneeid + "'/> </p> <p class= ' LISTP ' > <span class= ' user-name ' >" + sjson[j]. Consigneename + "</span> </p> <p class= ' listp ' id= ' listpconsigneeprovinceaddress ' >" + sjson[j]. Consigneeprovinceaddress + "</p> <p class= ' listp ' id= ' listpconsigneeaddress ' >" + sjson[j]. Consigneeaddress + "</p> <p class= ' listp ' id= ' listpmobophone ' > Cell phone:<span>" + sjson[j]. Mobophone + "</p></span><p class= ' listp ' id= ' listpconsigneepostcode ' > Zip code:<span>" + sJSon[j] . Consigneepostcode +"</span></p><s class= ' icon ' ></s> <input type= ' hidden ' value= '" + sjson[j]. Isdefault + "id= ' Addsel ' > </li>");
}
else {
$ ('. Myaddrlist '). Append ("<li class=" onclick= ' Selectedli (this) ' onmouseover= ' selectedlihover (this) ' onmouseout = ' Selectedliout (this) ' > <p class= ' address-name ' > <strong> "+ sjson[j]. Consigneeaddressname + "</strong> <span class= ' address-close ' onclick= ' Deleteconsignee (this) ' > delete </ span> <a class= ' address-edit ' onclick= ' Editconsignee (this) ' >[modify]</a> <input type= ' hidden ' value= ' " + Sjson[j]. Consigneeid + "'/> </p> <p class= ' LISTP ' > <span class= ' user-name ' >" + sjson[j]. Consigneename + "</span> </p> <p class= ' listp ' id= ' listpconsigneeprovinceaddress ' >" + sjson[j]. Consigneeprovinceaddress + "</p> <p class= ' listp ' id= ' listpconsigneeaddress ' >" + sjson[j]. Consigneeaddress + "</p> <p class= ' listp ' id= ' listpmobophone ' > Cell phone:<span>" + sjson[j]. Mobophone + "</p></span><p class= ' listp ' id= ' listpconsigneepostcode ' > Zip code:<span>" + sJSon[j] . Consigneepostcode + "</span></p><s class= ' icon ' ></s> <input type= ' hidden ' value= ' + sjson[j]. Isdefault + "id= ' Addsel ' > </li>");
}
}

}

Select Shipping Method
$ (document). Ready (function () {
Getsendwaymoney ();
$ (' #ContentPlaceHolder1_drpSendWay '). Change (function () {
var Sendwayid = $ (this). Find ("option:selected"). Val ();
var oxmlhppt = Createxmlhttp ();
var url = "jsonsendway.aspx?sendwayid=" + Sendwayid;
Oxmlhppt.open ("Get", url, True);
Oxmlhppt.onreadystatechange = function () {
if (oxmlhppt.readystate = = 4)//xmlhttp.readystate = 4 response completed; You can get and use the server's response
{
The Status property of the IF (oxmlhppt.status = =)//xmlhttprequest object is generally used to return the HTTP status code of the server. Status of 200 means "success"
{
Getjsondatasendway (Oxmlhppt.responsetext); Oxmlhppt.responsexml get the XML document
}
}
}
Oxmlhppt.send (NULL);
});
});
function Getjsondatasendway (data) {
var Sjson = eval ("(" + Data + ")");
var provinceadress = $ (' #ContentPlaceHolder1_drpProvince option:selected '). Text ();

$ (' #desc1 '). Text (sjson.senddescribe);

};
Express Shipping
function Getsendwaymoney ()
{
var consigneeprovinceaddress = $ ('. Myaddrlist. Curr '). Find ("#listpConsigneeProvinceAddress"). Text ();
var DFETG = $ ('. Myaddrlist li '). attr ("ClassName");
var Subtotalmoney = $ (' #ContentPlaceHolder1_subtotalMoney '). Text ();
if ($.trim (consigneeprovinceaddress). Split ("") [0] = = "Shanghai") {
if (parsefloat (Subtotalmoney) > 99.00) {
$ (' #shipFee1 '). Text ("0.00");
$ (' #sendWayMoney '). Text ("0.00");
$ ('. pricec_red '). Text (Subtotalmoney);
}
else {
$ (' #shipFee1 '). Text ("10.00");
$ (' #sendWayMoney '). Text ("10.00");
$ ('. pricec_red '). Text ((parsefloat (Subtotalmoney) + 10.00));
}
}
else {
if (parsefloat (Subtotalmoney) > 299.00) {
$ (' #shipFee1 '). Text ("0.00");
$ (' #sendWayMoney '). Text ("0.00");
$ ('. pricec_red '). Text (Subtotalmoney);
}
else {
$ (' #shipFee1 '). Text ("15.00");
$ (' #sendWayMoney '). Text ("15.00");
$ ('. pricec_red '). Text ((parsefloat (Subtotalmoney) + 10.00));
}
}
}

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.