Jquery运行我的ziptastic慢

时间:2014-07-28 14:53:29

标签: javascript jquery

当我的客户输入他们的邮政编码时,输出数据(城市和州)的加载速度非常慢。他们必须非常慢地填写邮政编码,以便显示城市和州的数据字段。这里的任何帮助都很棒,是网站的功能代码。

(function( $ ) {
    var requests = {};
    var zipValid = {
            us: /[0-9]{5}(-[0-9]{4})?/
    };

    $.ziptastic = function(zip, callback){
            // Only make unique requests
            if(!requests[zip]) {
                    requests[zip] = $.getJSON('http://zip.elevenbasetwo.com/v2/US/' + zip);
            }

            // Bind to the finished request
            requests[zip].done(function(data) {
                    callback(data.country, data.state, data.city, zip);
            });

            // Allow for binding to the deferred object
            return requests[zip];
    };

    $.fn.ziptastic = function( options ) {
            return this.each(function() {
                    var ele = $(this);

                    ele.on('keyup', function() {
                            var zip = ele.val();

                            // TODO Non-US zip codes?
                            if(zipValid.us.test(zip)) {
                                    $.ziptastic(zip, function(country, state, city) {
                                            // Trigger the updated information
                                            ele.trigger('zipChange', [country, state, city, zip]);
                                    })
                            }
                    });
            });
    };
})( jQuery );




    <?php
session_start();
include "include.php";

if(isset($_SESSION['memberID'])){
    $memberID = $_SESSION['memberID'];
    $factory = new TypeFactory($dbName);
    $o = $factory->get_object($memberID,"MEMBER");
}else{
    header("location:index.php");
}
// check if any order placed or not to get default address
    $sql12 = "select * from ORDERS where memberID =".$memberID." order by pickupDATE DESC";
    $res12 = getXbyY($sql12,"array");
    $row12 = count($res12);

    if($row12>2){
        if($res12[0]['f_countryID']!="" &&  $res12[0]['f_stateID']!="" &&  $res12[0]['f_cityID']!="" &&  $res12[0]['f_zipcode']!="" &&  $res12[0]['t_countryID']!="" && $res12[0]['t_stateID']!="" && $res12[0]['t_cityID'] && $res12[0]['t_zipcode']!=""){
            $default =1;
        }else{

        $default =0;
        }
    }
    if($o->memberID>0){
        $totalcarrier = gettotalmembercarrier($o->memberID);

    }


if(isset($_GET['msgID'])){
    $msgID = $_GET['msgID'];
}else{
    $msgID= 0;
}

$date1 = todayDateY();
$p1 = explode("-",$date1);
$year = $p1[0];
$month = $p1[1];
$date = $p1[2];
$value = $month."/".$date."/".$year;

$sql ="select * from MEMBER_CARRIER_LOGIN where memberID =".$_SESSION['memberID']." and isACTIVE = 1";
$res = getXbyY($sql,"array");
$row = count($res);


if($_POST['Submit'] == "Submit"){

    if($_POST['f_stateID'] =="" || $_POST['f_cityID'] =="" || $_POST['f_countryID'] == "" || $_POST['t_stateID'] =="" || $_POST['t_cityID'] =="" || $_POST['t_countryID'] == ""){
            header("location:calculator.php?msgID=175");
    }elseif($totalcarrier == 0){
            header("location:calculator.php");
    }else{
        $counter = 0;
        $_SESSION['order'][$counter]['shippingmode'] = $_POST['shippingmode'];
        $_SESSION['order'][$counter]['location'] = $_POST['location'];
        $_SESSION['order'][$counter]['ordername'] = $_POST['ordername'];
        $_SESSION['order'][$counter]['unit'] = $_POST['unit'];
            if($_SESSION['order'][$counter]['unit'] == 1){
                $_SESSION['order'][$counter]['weight_unit'] = "kg";
                $_SESSION['order'][$counter]['dimesions'] = "cm";
            }else{
                $_SESSION['order'][$counter]['weight_unit'] = "lb";
                $_SESSION['order'][$counter]['dimesions'] = "in";
            }   
        $_SESSION['order'][$counter]['weight'] = $_POST['weight'];
        $_SESSION['order'][$counter]['height'] = $_POST['height'];  
        $_SESSION['order'][$counter]['width'] = $_POST['width'];
        $_SESSION['order'][$counter]['len_gth'] = $_POST['len_gth'];    
        $_SESSION['order'][$counter]['shipmentID'] = $_POST['shipmentID'];  
        $_SESSION['order'][$counter]['f_address'] = $_POST['f_address'];
        $_SESSION['order'][$counter]['f_countryID'] = $_POST['f_countryID'];
        // to get country 
        /*if($_POST['f_countryID']!="" && $_POST['f_countryID'] >0){    
            $_SESSION['order'][$counter]['f_country'] = getcountryABBR($_POST['f_countryID']);
        }*/

        $_SESSION['order'][$counter]['f_stateID'] = $_POST['f_stateID'];
        $_SESSION['order'][$counter]['f_cityID'] = $_POST['f_cityID'];

        if($_POST['isDEFAULT']!=""){
            $_SESSION['order'][$counter]['f_zipcode'] = $_POST['f_zipcode'];
        }else{
            $_SESSION['order'][$counter]['f_zipcode'] = $_POST['f_zipcode1'];
        }
        $_SESSION['order'][$counter]['t_address'] = $_POST['t_address'];    
        $_SESSION['order'][$counter]['t_countryID'] = $_POST['t_countryID'];
        /*if($_POST['t_countryID']!="" && $_POST['t_countryID'] >0){    
            $_SESSION['order'][$counter]['t_country'] = getcountryABBR($_POST['t_countryID']);
        } */


        $_SESSION['order'][$counter]['t_stateID'] = $_POST['t_stateID'];
        $_SESSION['order'][$counter]['t_cityID'] = $_POST['t_cityID'];
        $_SESSION['order'][$counter]['t_zipcode'] = $_POST['t_zipcode'];
        $_SESSION['order'][$counter]['pickup'] = $_POST['datepicker'];
        $_SESSION['order'][$counter]['class'] = $_POST['class'];
        $_SESSION['order'][$counter]['role'] = $_POST['role'];
    /*  $p2 = explode("/",$dates);
        $month = $p2[0];
        $date = $p2[1];
        $year = $p2[2];
        $values = $month."-".$date."-".$year; */
        //$_SESSION['order'][$counter]['pickup'] = $dates;

        $_SESSION['order'][$counter]['orderMADEON'] = todaysDate();

        $_SESSION['order'][$counter]['senderNAME'] = $_POST['senderNAME'];
        $_SESSION['order'][$counter]['recipientNAME'] = $_POST['recipientNAME'];
        $_SESSION['order'][$counter]['isACTIVE'] = 2;
        $_SESSION['order'][$counter]['isDEFAULT'] = $_POST['isDEFAULT'];

        $_SESSION['order'][$counter]['f_company'] = $res[0]['f_company'];
        $_SESSION['order'][$counter]['f_email'] = $res[0]['f_email'];
        $_SESSION['order'][$counter]['f_location'] = $res[0]['f_location'];
        $_SESSION['order'][$counter]['f_address'] = $res[0]['f_address'];
        $_SESSION['order'][$counter]['f_phonenumber'] = $res[0]['f_phonenumber'];


        $_SESSION['order'][$counter]['t_company'] = $res[0]['t_company'];
        $_SESSION['order'][$counter]['t_email'] = $res[0]['t_email'];
        $_SESSION['order'][$counter]['t_location'] = $res[0]['t_location'];
        $_SESSION['order'][$counter]['t_address'] = $res[0]['t_address'];
        $_SESSION['order'][$counter]['t_phonenumber'] = $res[0]['t_phonenumber']; 


        $_SESSION['order'][$counter]['senderNAME'] = $res[0]['senderNAME']; 
        $_SESSION['order'][$counter]['recipientNAME'] = $res[0]['recipientNAME']; 

            header("location:companies.php?rates=0");
        }
}

$msg= getERRORS($msgID);

include"includes/header.php";
include"html/calculator.php";
include"includes/footer.php";
?>

0 个答案:

没有答案