Failed to load resource: the server responded with a status of 500 (Internal Server Error) localhost:45562/WebService1.asmx/btn
WebService not load via ajax call, if I write same code in WebForm.aspx.cs everything work nice
WebForm1.aspx
$(document).ready(function () {
$("#btn").click(function () {
sendAjaxRequest();
});
function sendAjaxRequest() {
$.ajax({
async: true,
url: "WebService1.asmx/btn",
type: "POST",
data: "{ surname: 'Axakalov', name: 'Sunnatilla' }",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: responseOut,
error: function (error) {
debugger;
alert(error);
}
});
};
function responseOut(response) {
$("#out").html(response.d);
}
});
WebService1.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebApplication9
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string btn(string surname, string name)
{
return surname + " " + name;
}
}
}
Please help, why webservcise1.asmx was not found
Considering that you have given correct URL then..
You need to enable [System.Web.Script.Services.ScriptService]
attribute:
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string btn(string surname, string name)
{
return surname + " " + name;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.