2014-01-26 2 views
0

나는 html 태그를 채울 웹 서비스가 있습니다. asp.net 웹 서비스 2를 반환

[WebMethod] 
public string GetHelloMessage(string country) 
{ 
string test = "<div>amin</div>"; 
return test; 
} 

및 JQuery와

은 다음과 같습니다

url: ServiceUrl, 
    type: "POST", 
    contentType: "application/json; charset=utf-8", 
    dataType: "jsonp", 
    timeout: 15000, 
    success: function (d) { 
     if (d.length > 0) { 
      var c = JSON.parse(d); 
      if ($(".test1div").length) { 
       $(".test1div").html(c.Content1) 
      }if ($(".test2div").length) { 
       $(".test2div").html(c.Content2) 
      } 

방법 test2div 태그를 채우기 위해 웹 서비스를 코딩? 웹 서비스에서 텍스트를 반환하는 방법 예 :

string Content1 = "<div>amin</div>"; 
string Content2 = "<div>reza</div>; 
string Content3 = Content1 + Content2; 
return Content3; 

자세한 설명을 도와주세요.

답변

0

그것의 쉬운 당신은 더 사용 목록에 대한 해결책이

if ($(".testreturn").length) { 
     $(".testreturn").html((data.d).split('$')[0]) 
} 
} if ($(".test2return").length) { 
     $(".test2return").html((data.d).split('$')[1]) 
} 

당신이 찾고 있던 클라이언트 스크립트에서이 문자열을 분할

string test = "<div id='test_tag'>amin</div>$<div id='test_tag'>amin2</div>"; 
return test; 

같은 문자열을

를 연결할 수 있습니다 이와 같은 수익과 프로세스가 아래에서 발생했습니다.

$.ajax({ 
    type: "POST", 
    url: "MyWebService.asmx/SayAllTheHellos", 
    data: "{ firstName: 'Aidy', lastName: 'F' }", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function (data) { 
     var myData = data.d; 
     alert(myData.length + " hellos"); 
     for (var i = 0; i < myData.length; i++) { 
      alert(myData[i]); 
     } 
    } 
}); 
+0

이 명령으로 어떻게 할 수 있습니까? var c = JSON.parse (d); –

+0

코드 편집 후 – Trikaldarshi

+0

처럼 다시 사용할 수 있습니다. 나는 나의 요구를 더 편집하고 설명했다. –