2011-12-29 7 views
1

私には2つの問題があります。まず、ログインボタンをクリックすると、localhostは私に許可を与えたいと思う。突然1秒で消える。ダブルクリックすると、常にこのように下部に表示されます。次にAjaxメソッドを実行します。私はこのウィンドウをワンクリックで常に表示したい。どうすればajaxメソッドのtextBox値に到達できますか?

私の2番目の問題は、私はajaxメソッドでtxtUserNameに到達したいと思います。私はこれにどのようにわからない。

error

背後にあるコード:

[System.Web.Services.WebMethod] 
    public static string SendLocation(object Latitude, object Longitude) 
    { 
     Core dal_ = new Core(); 
     Model.Team obj_ = new Model.Team(); 

     //obj_.UserName = ????? 
     obj_.Latitude = Convert.ToDecimal(Latitude); 
     obj_.Longitude = Convert.ToDecimal(Longitude); 

     dal_.UpdateTeamCoordinat(obj_); 
     return ""; 
    } 

のJavaScript(asp.x中):

<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
<script src="js/yqlgeo.js"></script> 
<script type="text/javascript"> 

    function initiate_geolocation() { 
     if (navigator.geolocation) { 
      navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors); 
     } 
     else { 
      yqlgeo.get('visitor', normalize_yql_response); 
     } 
    } 

    function handle_errors(error) { 
     switch (error.code) { 
      case error.PERMISSION_DENIED: alert("user did not share geolocation data"); 
       break; 

      case error.POSITION_UNAVAILABLE: alert("could not detect current position"); 
       break; 

      case error.TIMEOUT: alert("retrieving position timedout"); 
       break; 

      default: alert("unknown error"); 
       break; 
     } 
    } 

    function normalize_yql_response(response) { 
     if (response.error) { 
      var error = { code: 0 }; 
      handle_error(error); 
      return; 
     } 

     var position = { 
      coords: 
     { 
      latitude: response.place.centroid.latitude, 
      longitude: response.place.centroid.longitude 
     }, 
      address: 
     { 
      city: response.place.locality2.content, 
      region: response.place.admin1.content, 
      country: response.place.country.content 
     } 
     }; 
     handle_geolocation_query(position);  
    } 

    function handle_geolocation_query(position) { 
     PageMethods.SendLocation(position.coords.latitude, position.coords.longitude); 
    } 
</script> 

Asp.x:

<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox> 
    <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox> 
    <asp:Button ID="LoginButton" runat="server" Text="Log In" OnClientClick="initiate_geolocation()" 
       OnClick="LoginButton_Click" /> 
+0

txtUserNameに到達したいAjaxの方法を教えてください。 – adatapost

+0

in codebehind、SendLocation ajaxメソッド – ozkank

+0

このWebメソッドはコード内でどこに要求されていますか? – adatapost

答えて

0

webMethodで要素を選択しようとしていますか?私はそれが不可能と思うだろう

私はほとんどのWebMethodsをFireAndForgetタイプの機能として使用します。

あなたが機能を発射した後、テキストボックスを選択したい場合、私はあなたが要素でやりたいことに応じて、JavaScriptの

function handle_geolocation_query(position) { 
    PageMethods.SendLocation(position.coords.latitude, position.coords.longitude); 

    //If have JQuery 
    var textbox = $('#' + <%=txtUserName.ClientID %>); 

    //otherwise 
    document.getElementById(<%=txtUserName.ClientID %>);  
} 

を使用して、それを選択することになるjQueryのルートを気にするかどうかによって異なります。

1

あなたは、AJAXを更新することができます電話:

PageMethods.SendLocation($("#txtUserName").val(), position.coords.latitude, position.coords.longitude); 

また、パラメータをWebメソッドにも追加する必要があります。

関連する問題