我有一个问题,我使用ajax消费web服务,它没有带来所有日期特定数据咨询数据库,但是我在测试模式下测试Web服务它工作正常,这是我的代码,什么可能是问题?
这是我的网络服务代码
[WebMethod]
public string GetName(String name)
{
var RegisteredUsers = new List<Person>();
String nombre = "";
String enStock = "";
int id = 1;
if (Connect())
{
Items oItem = (SAPbobsCOM.Items)oCompany.GetBusinessObject(BoObjectTypes.oItems);
if (oItem.GetByKey(name))
{
nombre = oItem.ItemName;
enStock = oItem.QuantityOnStock.ToString();
id = 3;
}
id = 0;
}
var json = "";
RegisteredUsers.Add(new Person() { PersonID = id, Name = nombre, stock = name });
var serializer = new JavaScriptSerializer();
json = serializer.Serialize(RegisteredUsers);
return json;
}
这是正常测试中Web服务结果的图像 结果是正确的,它带给我所有的数据 enter image description here
但是我在ajax上进行测试它没有给我带来所有数据,可能是什么问题? enter image description here
这是我的网络配置代码:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/>
</modules>
</system.webServer>
</configuration>
这是我的AJAX HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="js1/jquery-1.4.2.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
var dataString = 'name="1000066"';
$.ajax({
type: "POST",
url: "WebService1.asmx/GetName",
data: dataString,
success: function(data) {
console.log(data);
},
error: function(xhr, status, error) {
alert(error);
alert(status);
},
complete: function(xData, status) {
$('#txt').html($(xData.responseXML).text()); // result
}
});
</script>
</head>
<body>
1000066
<div id="resultado_json"></div>
<div id="txt"></div>
<form target="_blank" action='http://190.185.126.6:8092/WebService1.asmx/GetName' method="POST">
<table cellspacing="0" cellpadding="4" frame="box" bordercolor="#dcdcdc" rules="none" style="border-collapse: collapse;">
<tr>
<td class="frmHeader" background="#dcdcdc" style="border-right: 2px solid white;">Parameter</td>
<td class="frmHeader" background="#dcdcdc">Value</td>
</tr>
<tr>
<td class="frmText" style="color: #000000; font-weight: normal;">name:</td>
<td><input class="frmInput" type="text" size="50" name="name"></td>
</tr>
<tr>
<td></td>
<td align="right"> <input type="submit" value="Invoke" class="button"></td>
</tr>
</table>
</form>
</body>
</html>