Я не знаю, почему я получаю сообщение об ошибке при вызове метода ajax. Веб-сервис работает нормально. Я разместил на своей локальной машине и проверил. Любая помощь приветствуется.Невозможно вставить значения в базу данных с помощью ajax-вызова
Web Service Code:
public class Contacts : System.Web.Services.WebService
{
[WebMethod]
public void InsertIntoContacts(string name,string email,string message)
{
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["KarthikDBConnString"].ConnectionString;
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand cmd = new MySqlCommand("Insert into contacts values(@name , @email , @message)");
cmd.Connection = connection;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@message", message);
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
}
}
HTML-разметка форме:
<form role="form" id="contactForm">
<div class="form-group">
<label for="name">Name :</label>
<input type="text" class="form-control" placeholder="Enter your Name" id="name" />
</div>
<div class="form-group">
<label for="email">Email :</label>
<input type="email" class="form-control" placeholder="Enter your Email here (optional)" id="email" />
</div>
<div class="form-group">
<label for="message">Message :</label>
<textarea class="form-control" rows="3" placeholder="Enter your message here" id="message"></textarea>
</div>
<div class="form-group">
<button type="button" class="btn btn-primary" id="sendMsgBtn" onclick="javascript:SendMsg()">Send Message</button>
</div>
</form>
И вызов Ajax является:
function SendMsg() {
var soapRequset = '<?xml version="1.0" encoding="utf-8"?>\
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\
<soap:Body>\
<InsertIntoContacts xmlns="http://tempuri.org/">\
<name>'+$("#name").val()+'</name>\
<email>'+$("#email").val()+'</email>\
<message>'+$("#message").val()+'</message>\
</InsertIntoContacts>\
</soap:Body>\
</soap:Envelope>';
$.ajax({
url: "host/contacts.asmx",
type: "POST",
data: soapRequset,
contentType: "text/xml; charset=utf-8",
dataType: "xml",
processData: false,
success: function (xData, status) { alert(status) },
error: function (xData, status, req) {
alert(xData.status);
alert(status);
alert(req);
}
});
}
Что именно эта ошибка говорит ?? – Rohit416
Первое предупреждение говорит об ошибке. Второе предупреждение говорит undefined – Karthik
проверить, какой код состояния вы получаете, то есть '404',' 400' или '500' ?! – Rohit416