2012-03-10 17 views
0

私はここに、おそらく簡単です奇妙な問題は、コードAJAX/ASP.NETの問題

JSが

function visitorAction(firstnm,lastnm) 
{ 

    var xmlhttp; 


    xmlhttp=new XMLHttpRequest(); 


    xmlhttp.onreadystatechange=function() 
    { 
    if(xmlhttp.readyState==4 && xmlhttp.status==200) 
     { 
      document.getElementById('placeholder').innerHTML=xmlhttp.responseText; 

     } 

    } 

    xmlhttp.open("GET", "Handler1.ashx?firstname="+firstnm+"&lastname="+lastnm, true); 
    xmlhttp.send(); 
} 

私のWebフォームファイルである必要があります - はいJSファイルが正しく

と呼ばれています
<form id="form1" runat="server"> 
    <div> 
    <table> 
      <tbody> 
       <tr> 
        <td>First Name</td> 
        <td><asp:TextBox ID="firstnameTextBox" runat="server"></asp:TextBox></td> 
        <td><asp:RequiredFieldValidator 
        ID="RequiredFieldValidator1" 
        runat="server" 
        ErrorMessage="Fill in your first name" 
        ControlToValidate="firstnameTextBox"></asp:RequiredFieldValidator></td> 
       </tr> 
       <tr> 
        <td>Last Name</td> 
        <td><asp:TextBox ID="lastnameTextBox" runat="server"></asp:TextBox></td> 
        <td><asp:RequiredFieldValidator 
         ID="RequiredFieldValidator2" 
         runat="server" 
         ErrorMessage="Fill in your last name" 
         ControlToValidate="lastnameTextBox"></asp:RequiredFieldValidator></td> 
       </tr> 
      </tbody> 
     </table> 
     <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return visitorAction('firstnameTextBox','lastnameTextBox');">Login</asp:LinkButton> 
     <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl="Registration.aspx">Register</asp:LinkButton> 
    </div> 
    <div id = "placeholder"> 

    </div> 

私のハンドラ

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace CSC515_Project5_GREGORY 
{ 

    public class Handler1 : IHttpHandler 
    { 

     public void ProcessRequest(HttpContext context) 
     { 

      context.Response.ContentType = "text/html"; 
      context.Response.Write("<html>"); 
      context.Response.Output.WriteLine("hello"); 
      context.Response.Write("</html>"); 

     } 

     public bool IsReusable 
     { 
      get 
      { 
       return false; 
      } 
     } 
    } 
} 

私の問題は、関数が、私は私の入力フィールドには何を記入する際に動作し、「ログイン」をクリックしないことです。テストのために "hello"を返すだけですが、何も起こらず、コンソールエラーも発生しません。どんなフィールドにも記入することなく「ログイン」をクリックすると、それは何をすべきかを行います。何を与える?

+0

オフ小さな話題の使用http://docs.jquery.com/API/1.1/AJAX AJAXあなたのコードのクロスbrowserx機能に追加し、それを呼び出すため。 –

答えて

2

ハンドラ内の<html>部分を削除します。 context.Response.Output.WriteLine("hello");で十分です。 how to use ajax in asp.net applicationsの詳細については、このサイトを参照してください。

+0

なしサイコロ:/私は疑問に言ったように、私が入力したデータを持っていないとき、それは動作します。 – user975044

+0

はfalseを返す '置く;' 'xmlhttp.send後();'。 –

+1

:)ありがとうございます!私はそれが何か単純であることを知っていた – user975044