2014-12-05 1 views
0

내 프로젝트에 FlexiGid를 사용하고 있습니다. 그러나 문제는 WebMethod가 실행되지 않습니다. (Json/Ajax 호출) Webmethod에 디버그 지점을 넣었지만 실행 중이 아니며 방화 광구가 웹 메소드 URL이 맞습니다. 여기FlexiGrid에서 웹 메서드가 실행되지 않음

내가 코드

아약스 전화가 방화범 후

function flexgrid() { 
     debugger; 
     $("#flex1").flexigrid({ 

        url: '/WebMethods.aspx/GetIssueSummaryById', 
        dataType: 'json', 
        contentType: "application/json; charset=utf-8", 
        colModel : [ 
         {display: 'ID', name : 'id', width : 40, sortable : true, align: 'center'}, 



        ], 
        data: JSON.stringify({ ProjectId: "1", UserId: "1" }), //Hard code this values at this time 
        buttons : [ 
         { name: 'Add', bclass: 'add', onpress: test }, 
         { name: 'Delete', bclass: 'delete', onpress: test }, 
         {separator: true}, 
         {name: 'A', onpress: sortAlpha}, 
         {name: 'B', onpress: sortAlpha} 


        ], 
        searchitems : [ 
         { display: 'Project', name: 'project' }, 
         {display: 'Name', name : 'name', isdefault: true} 
        ], 
        sortname: "id", 
        sortorder: "asc", 
        usepager: true, 
        title: 'Issue Summary', 
        useRp: true, 
        rp: 10, 
        showTableToggleBtn: true, 
        width: 1000, 
        height: 500 
       }); 

    }; 

웹 방법 (WebMethods.aspx 파일에 먹으 렴)

[WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public static List<IssuesVM> GetIssueSummaryById(string UserId, string ProjectId) 
{ 
    //Guid LoggedInUserId = new Guid(UserId); 
    //int ProjectId = Convert.ToInt32(ProjectId); 

    List<IssuesVM> lst = new List<IssuesVM>(); 

    try 
    { 
     SqlCommand comIssueSummary = new SqlCommand("SP_GetIssuesByProjectIDAndOwnerId", conn); 
     comIssueSummary.CommandType = CommandType.StoredProcedure; 
     //comIssueSummary.Parameters.Add("@ProjectId", SqlDbType.Int).Value = ProjectId; 
     // comIssueSummary.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = LoggedInUserId; 
     if (conn.State == ConnectionState.Closed) 
      conn.Open(); 

     SqlDataReader rdr = comIssueSummary.ExecuteReader(); 
     DataTable dt = new DataTable(); 
     dt.Load(rdr); 
     foreach (DataRow r in dt.Rows) 
     { 
      //Some code goes here 
     } 

    } 
    catch (Exception) 
    { 

     throw; 
    } 

    return lst; 
} 

을이 Image Here

보여줍니다 뒀다

누구든지 th에 대한 오류를 알 수 있습니까? 뭐야? 웹 방식을 발사하지 않습니까?

P.S - 아래 게시물 [Click Here]에서 몇 가지 해결책을 보았습니다. 나는 flexigrid.js 파일을 보냈지 만 작동하지 않습니다. 여기

는 이동하는 것이 좋습니다 수 있습니다 오프 그래서 일단

$.ajax({ 
        contentType: "application/json; charset=utf-8", 
    data: "{}", // to pass the parameters to WebMethod see below 
        success: function (data) { 
         g.addData(data); 
        }, 
        error: function (XMLHttpRequest, textStatus, errorThrown) { 
         try { 
          if (p.onError) p.onError(XMLHttpRequest, textStatus, errorThrown); 
         } catch (e) {} 
        } 
       }); 
      }, 

답변

0

(변경 후)

$.ajax({ 
       type: p.method, 
       url: p.url, 
       data: param, 
       dataType: p.dataType, 
       success: function (data) { 
        g.addData(data); 
       }, 
       error: function (XMLHttpRequest, textStatus, errorThrown) { 
        try { 
         if (p.onError) p.onError(XMLHttpRequest, textStatus, errorThrown); 
        } catch (e) {} 
       } 
      }); 
     }, 

FlexiGrid.js (변경 전) 변경 FlexiGrid.js 파일입니다 이 파일을 WebService.asmx 파일로 복사하십시오. 그렇게하는 것이 최선의 관례입니다. .ASPX 페이지는 HTML/CSS/Javascript로 정상적으로 응답하고 .asmx는 JSON 또는 XML로 응답합니다.

첫 번째 Ajax 호출을 수행하는 메소드를 노출하기 위해 [WebMethod] 속성을 추가 할 때 Ajax가 flexigrid를 호출하는지 여부에 관계없이 WebService 또는 Web Forms 페이지에 대한 호출이 다소 어려울 수 있습니다. Ajax가 공개 WebMethod를 호출하는 것에 대해 다소 까다로운 내용이 있습니다. 까다로운 부분은 요청의 내용 유형과 요청이 JSON 또는 XML이고 응답이 JSON 또는 XML 인 경우 발생합니다.

$('#gridTablegSearchProperty').flexigrid({ 
     url: 'Services/WSgSearch.asmx/gridTablegSearchProperty', 
     colModel: [... 

당신은 내가 contentType이 나 Flexigrid의 데이터 유형 속성을 설정하지 않는 첫 번째 코드에서 알 수 :

그래서 난 내가 Flexigrid를 사용하는 프로젝트에 대한 일을 알고 무엇을 보여줄 것입니다.

그리고 지금 내의 WebMethod 서명

[WebMethod] 
    public XmlDocument gridTablegSearchProperty() 
    { 
     System.Collections.Specialized.NameValueCollection nvc = HttpContext.Current.Request.Form; 

     int pgNum = nvc.GetValueAsInteger("page").GetValueOrDefault(1); 
     int pgSize = nvc.GetValueAsInteger("rp").GetValueOrDefault(20); 
     string sortName = nvc.GetValueOrDefaultAsString("sortname", "key"); 
     string sortOrder = nvc.GetValueOrDefaultAsString("sortorder", "desc"); 

     string query = nvc.GetValueOrDefaultAsString("query", string.Empty); 
     string qtype = nvc.GetValueOrDefaultAsString("qtype", string.Empty); 

내의 WebMethod는이 .asmx 파일에, 당신이 파일 뒤에 코드에서 당신을 유지하는 경우 그것은 중요하지 않습니다하지만 난 WebService에로 이동 한 후, 웹 메쏘드를 드롭한다. aspx 이것은 가난한 명명 규칙 및 파일 사용 규칙입니다.

관련 문제