2009-09-10 3 views
2

나는 이것을 실행하는 많은 방법을 시도했지만 그럴 수는 없다 .. 여기에 거래가있다. 나는 테이블 행에 데이터를 표시하고, 모든 행은 내가 원하는 사람의 ID를 나타낸다. . jquery를 사용하여 버튼이있는 행에서이 ID를 수집합니다. 코드는 다음과 같습니다. 작업 방법은 내가 작성하려고하는 것입니다.Jquery 클래식 asp와의 POST 조합

나는 그것이 작동 경고 사용하여 테스트 할 때, 여기에 단순히 내가 Delete.aspx 여기

<% 

문자열 P = 요청의 내용이다 "값"]라는 파일이 붙어있어 어려운 부분이다; int pInt = Int32.Parse (p);

var dataContext = new CustomersDataContext(); 
var customer = from m in dataContext.Customers 
       where m.id == pInt 
       select m; 
dataContext.Customers.DeleteAllOnSubmit(customer); 
dataContext.SubmitChanges(); 
%> 

가 지금은 특정 ID로 사람을 삭제 Delete.aspx 값으로를 보내려고하고, 브라우저에서 Delete.aspx? 값 = 7을 입력하여 작동, 그것은 ID가 7 사람을 삭제 이제 여기에 내가 정말로 붙어있는 곳이있다. Default.aspx를에서 내가 Delete.aspx에 도달하고이 같은 사람의 ID를 사용하여 JQuery와 통과하기 위해 노력하고있어 : 내가 버튼을 클릭 내가 얻을 삭제를 확인하면, 이제 결과를

$(".btn-delete").click(function() { 
       var answer = confirm("If you press OK, this customer will be deleted?") 
       var customer_id = $(this).parents("tr").attr('id'); 
       if (answer) { 


         $.ajax({ 
        type: "POST", 
        url: "Delete.aspx", 
        data: "{value: '" + customer_id + "'}", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: function(msg) { 
        AjaxSucceeded(msg); 
        }, 
        error: AjaxFailed 

        }); 

        $(this).parents("tr").animate({ backgroundColor: "#fbc7c7" }, "fast") 
       .animate({ opacity: "hide" }, "slow") 
        return false; 
       } 
       else { 
        alert("Customer has not been deleted!") 
       } 


      }); 

      function AjaxSucceeded(result) { 
       alert(result.d); 
      } 
      function AjaxFailed(result) { 
       alert(result.status + ' ' + result.statusText); 
      } 

     }); 

을 "500 내부 서버 오류 ",이 고칠 수 있습니까 아니면 더 이상 같은 일을하는 다른 간단한 방법은 무엇입니까? 여기

.. 내가 너무 적어도 올바른 방향으로 날 지점 너무 가까이있어 기분이 ..

내가 코드를 수정 한


주셔서 감사합니다 ..하지만 여전히 나는 도움이 필요 여기 내 Delete.aspx

내 Delete.aspx.cs

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

namespace Second_Question 
{ 
    public partial class Delete : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

      string p = Request["value"]; 
      int pInt = Int32.Parse(p); 

      var dataContext = new CustomersDataContext(); 
      var customer = from m in dataContext.Customers 
          where m.id == pInt 
          select m; 
      dataContext.Customers.DeleteAllOnSubmit(customer); 
      dataContext.SubmitChanges(); 


     } 
    } 
} 

입니다3210

어떤 아이디어? 감사합니다.

+0

이 클래식 ASP 아니다 - 그것은 본다 C#처럼. 귀하의 질문과 태그가 올바르게 표현 되었습니까? –

+0

Page_Load 메서드에서 서버 측 코드가 발생합니까? –

+0

정말 모르겠다. 며칠 전부터 asp로 시작했다. 그 태그도 추가 할 것이다. – ant

답변

1

올바르게 컴파일되지 않았거나 처리되지 않은 예외가 발생하는 서버 측 코드가 있기 때문에 일반적으로 "500 Internal Server Error"가 발생합니다. 에서 [의 WebMethod] 속성으로 장식되어 특정 방법에 삭제 루틴을 이동

:

난 당신이 변화의 몇 가지를 시도 할 수 있습니다 제안합니다. 코드에 System.Web.Services가 포함되어 있는지 확인하십시오.

jQuery ajax 호출에 전체 페이지 대신 "/Delete.aspx/MyDeleteMethod"를 포함 시켰습니까?

이 애플리케이션의 보안에 대해 생각해 보셨습니까? 누군가가 귀하의 customer_id를 잡아서 Firebug로 변경하는 경우 어떻게됩니까?

편집 : 여기 내가 서버 측 코드를

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.Services 

namespace Second_Question 
{ 
    public partial class Delete : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     [WebMethod] 
     public static void DeleteCustomer(int CustID) 
     { 

      var dataContext = new CustomersDataContext(); 
      var customer = from m in dataContext.Customers 
          where m.id == CustID 
          select m; 
      dataContext.Customers.DeleteAllOnSubmit(customer); 
      dataContext.SubmitChanges(); 


     } 
    } 
} 

을 제안 그리고 내 jQuery를이 어떻게 보이는지 확인의 :

$.ajax({ 
     type: "POST", 
     url: "Delete.aspx/DeleteCustomer", 
     data: "{CustID: " + parseInt(customer_id) + "}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function(msg) { 
        AjaxSucceeded(msg); 
       }, 
     error: AjaxFailed 
}); 
+0

"이 jQuery 아약스 호출을 포함시켜주세요"/Delete.aspx/ MyDeleteMethod "를 사용하십시오." ? 감사합니다. – ant

+0

내가 추가 한 예제에서는 jQuery가 페이지를 직접 호출하지 않고 Delete.aspx 내에 특정 목적으로 작성된 웹 메소드를 호출하는 것을 보여줍니다. 이렇게하면 논리적으로 문제를 좀 더 구분할 수 있습니다. –

+0

위대한 작품 : 감사합니다 – ant