2016-03-18 4 views
0

Ich habe eine JavaScript-Funktion, die onClick über jquery ausgeführt wird. Innerhalb dieser Funktion rufe ich einen Web Service "getTestConnection" auf, der ein True oder False zurückgibt und ich habe bestätigt, dass es funktioniert, aber die Variable immer undefiniert zurückgibt.Variable mit Web-Service-Ergebnissen füllen

 $("#btnNext2").click(function() { 
 
     var postData = {}; { 
 
      postData['user'] = user; 
 
      postData['password'] = password; 
 
      postData['serviceurl'] = serviceurl; 
 
      postData['datasource'] = datasource; 
 
     }; 
 
     //Converts object to string and formats to JSON 
 
     var json = JSON.stringify(postData); 
 

 
     //connTest keeps getting returned as 'Undefined' 
 
     var connTest = getTestConnection(json); 
 

 
     }); 
 

 

 
     < script type = "text/javascript" > 
 
     function getDocType(json, rowcount) { 
 

 
      $.ajax({ 
 
      type: "POST", 
 
      url: "http://localhost:64580/Web_Services/WebServiceLibrary.asmx/GetDocTypes", 
 
      data: json, 
 
      contentType: "application/json; charset=utf-8", 
 
      dataType: "json", 
 
      success: function(data) { 
 

 
       //***************************************************************************** 
 
       //This is being called immediately after getTestConnection is executed 
 
       //******************************************************************************   
 
       for (i = 0; i < data.d.length; i++) { 
 
       $('#SelectDocType' + rowcount + '') 
 
        .append($("<option></option>") 
 
        .attr("value", data.d[i].docTypeID) 
 
        .text(data.d[i].docTypeName)); 
 
       } 
 
       var firstDocTypeID = data.d[0].docTypeID; 
 
       var jsonUnstringify = JSON.parse(json); 
 
       var postDataNew = {}; { 
 
       postDataNew['user'] = jsonUnstringify.user; 
 
       postDataNew['password'] = jsonUnstringify.password; 
 
       postDataNew['serviceurl'] = jsonUnstringify.serviceurl; 
 
       postDataNew['datasource'] = jsonUnstringify.datasource; 
 
       postDataNew['docTypeID'] = firstDocTypeID; 
 
       }; 
 
       var jsonnew = JSON.stringify(postDataNew); 
 

 
       getKeywords(jsonnew, rowcount); 
 

 
      }, 
 
      error: function(data) { 
 
       alert("***********Error***********" + data.responseText); 
 
      }, 
 
      failure: function(data) { 
 
       alert("***********Failure***********" + data.responseText); 
 
      } 
 
      }); 
 
      //Test Connection Web Service 
 
      function getTestConnection(json) { 
 

 
      $.ajax({ 
 
       type: "POST", 
 
       url: "http://localhost:64580/Web_Services/WebServiceLibrary.asmx/TestConnection", 
 
       data: json, 
 
       contentType: "application/json; charset=utf-8", 
 
       dataType: "json", 
 

 
       if (data.d == 'True') { 
 

 
        return true; 
 
       } else { 
 
        return false; 
 

 
       } 
 

 
       }, 
 
       error: function(data) { 
 
       alert("***********Error***********" + data.responseText); 
 
       }, 
 
       failure: function(data) { 
 
       alert("***********Failure***********" + data.responseText); 
 
       } 
 
      }); 
 
     } 
 

 
     < /script>

+0

Sie haben ein "