2
頁面中有一個像HTML這樣的選項卡式面板,其中每個選項卡點擊都會顯示不同的數據。 試圖用Ajax調用完成此操作。
在Visual Studio項目中,我創建了一個web服務test.asmx,裏面的服務文件夾。所以上發佈,它被保存在wwwroot/MyApp/Website/Services/test.asmx
如何在Sitecore中創建Web服務
asmx.cs
[System.Web.Script.Services.ScriptService]
public class test : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
ASCX
<asp:ScriptManager ID="_scriptManager" runat="server">
<Services>
<asp:ServiceReference Path="/Services/test.asmx" />
</Services>
</asp:ScriptManager>
<script type="text/javascript">
jQuery(function ($) {
console.log("howdy"); //this does print
var Param1 = 'one';
var Param2 = 'two';
$.ajax({
type: "GET",
url: "/Services/test.asmx/HelloWorld",
data:"",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "true",
cache: "false",
success: function (msg) {
alert(msg.d);
},
Error: function (x, e) {
alert("errrrr");
}
});
});
</script>
在瀏覽網頁,有這種錯誤在瀏覽器控制檯。
GET http://MyApp/Services/test.asmx/HelloWorld 500(內部服務器錯誤 )jQuery.noconflict.js:16
- 這是撥打電話
- 是不是因爲prototype.js中的正確方法衝突(不再是!!)。我已經說過
jQuery(function ($) {
...,但仍然.....