English 中文(简体)
ASP.NET Javascript Zip Codewatchup for CIty and State w/ Mootools, jQuery, or Ajax
原标题:ASP.NET Javascript Zip Code Lookup for CIty and State w/ Mootools, jQuery, or Ajax

I m试图撰写《Javascript Zip法典》研究效用。

(1) 用户将从下降中选择一个国家。

2) 之后,根据选定的国家,该市的唐纳德人将居住。

3) 之后,根据《国家法》和《泽伊法》加入相应的《泽西法》文本箱。 NET page。

问题:我没有界定错误要求,在选择一个国家时,这种要求导致申请屈服。

What should I cahnge in the following code?

  <script language="javascript">
   var request = new Request();
   var url = "";

   function getZipCode()
   {    
request.GetNoCache(url + "getZipCode.aspx?City=" +document.getElementById("drpCity").options[document.getElementById("drpCity").selectedIndex].value+ "&State=" +document.getElementById("drpStateSearch").options[document.getElementById("drpStateSearch").selectedIndex].value,      
function(result)
{
    if (result.readyState!=ReadyState.Complete)
        return;             
    if (result.status==HttpStatus.OK && result.responseText != "")
    {
        var zip = result.responseText;
        document.getElementById("txtZip").value = zip;
    }
    else
    {
        document.getElementById("txtZip").value = "No Zip Found";
    }
}
)
  }



   function selectCity()
   {    
request.GetNoCache(url + "getCities.aspx?State=" +document.getElementById("drpStateSearch").options[document.getElementById("drpStateSearch").selectedIndex].value,         

function(result)
{

    if (result.readyState!=ReadyState.Complete)
        return;             
    if (result.status==HttpStatus.OK && result.responseText != "")
    {
        var cities = result.responseText;
        var city_array=cities.split(",");
        var len = document.getElementById("drpCity").options.length;

        for( var j=len; j>=0;j--)
        {
            document.getElementById("drpCity").options[j]=null;
        }

        var option_i = new Option("--Select--","--Select--");
        document.getElementById("drpCity").options[0] = option_i;

        for(var i=1; i<=city_array.length-1;i++)
        {
            var option_c = new Option(city_array[i-1],city_array[i-1]);
            document.getElementById("drpCity").options[i] = option_c;
        }
    }
    else
    {
        var option_c = new Option("No City","");
        document.getElementById("drpCity").options[0] = option_c;
    }
}
)
   }

            </script>
   <script language="javascript" type="text/javascript">
   <!--
function __doPostBack(eventTarget, eventArgument) {
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
        theform = document.Form2;
    }
    else {
        theform = document.forms["Form2"];
    }
    theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
}
   // -->
   </script>

            City: <select id="drpStateSearch" name="drpStateSearch" 
                onchange="Javascript:selectCity();" style="width: 120px;">
                <option value="">---Select---</option>
                <option value="AK">Alaska</option>
                <option value="AL">Alabama</option>
                <option value="AR">Arkansas</option>
                <option value="AZ">Arizona</option>
                <option value="CA">California</option>
                <option value="CO">Colorado</option>
                <option value="CT">Connecticut</option>
                <option value="DC">District of Columbia</option>
                <option value="DE">Delaware</option>
                <option value="FL">Florida</option>
                <option value="GA">Georgia</option>
                <option value="HI">Hawaii</option>
                <option value="IA">Iowa</option>
                <option value="ID">Idaho</option>
                <option value="IL">Illinois</option>
                <option value="IN">Indiana</option>
                <option value="KS">Kansas</option>
                <option value="KY">Kentucky</option>
                <option value="LA">Louisiana</option>
                <option value="MA">Massachusetts</option>
                <option value="MD">Maryland</option>
                <option value="ME">Maine</option>
                <option value="MI">Michigan</option>
                <option value="MN">Minnesota</option>
                <option value="MO">Missouri</option>
                <option value="MS">Mississippi</option>
                <option value="MT">Montana</option>
                <option value="NC">North Carolina</option>
                <option value="ND">North Dakota</option>
                <option value="NE">Nebraska</option>
                <option value="NH">New Hampshire</option>
                <option value="NJ">New Jersey</option>
                <option value="NM">New Mexico</option>
                <option value="NV">Nevada</option>
                <option value="NY">New York</option>
                <option value="OH">Ohio</option>
                <option value="OK">Oklahoma</option>
                <option value="OR">Oregon</option>
                <option value="PA">Pennsylvania</option>
                <option value="RI">Rhode Island</option>
                <option value="SC">South Carolina</option>
                <option value="SD">South Dakota</option>
                <option value="TN">Tennessee</option>
                <option value="TX">Texas</option>
                <option value="UT">Utah</option>
                <option value="VA">Virginia</option>
                <option value="VT">Vermont</option>
                <option value="WA">Washington</option>
                <option value="WI">Wisconsin</option>
                <option value="WV">West Virginia</option>
                <option value="WY">Wyoming</option>
            </select> <br />
            State: <select id="drpCity" name="drpCity" onchange="javascript:getZipCode()">
                <option selected="">Select State to Populate</option>
            </select>
            <br />
            <table id="Table6" border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td height="28" width="38%">
                        Zipcode:</td>
                    <td height="28" width="62%">
                        <input id="txtZip" name="txtZip" type="text" /></td>

感谢!

最佳回答

你们是否使用MooTools? 如果需要的话,请你在你试图提出新申请之前确定模拟物。 如果没有要求,就不必提出适当的反对,以提出贾克斯请求。

if(window.XMLHttpRequest){
   request = new XMLHttpRequest();
}else if(window.ActiveXObject)
{
   request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("GET", url, true);
request.onreadystatechange = callback;
request.send(null);
function callback()
{
   if(request.readyState == 4)
   {
       if(request.status == 200)
       {
             /* do your call back stuff here */
       }
    }
 }

说明确实是基本和痛苦的类型,我建议利用 j或 Mo等框架,向你的服务器编码打电话。

/****** UPDATE *******************/ Here is the code for a basic Jquery ajax request:

$.ajax({ url: "test.html", 
         context: document.body, 
         data:{"info":"I m sending this back to the server"}, 
         success: function(data){ 
              /* do your callback stuff here */ 
         },
         error(jqXHR, textStatus, errorThrown){
              /* let s you know where you went wrong */
         }
});

The api def is

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!