使用ajax将数据从html表单传递到c#webservice
我在phpstorm中使用bootstrap创建了一个表单html,我想使用ajax将信息传递给c#webservice。 但是我对在ajax url中放置什么有一些疑问(如下面所示) 这是我的html/引导表单:使用ajax将数据从html表单传递到c#webservice,c#,jquery,html,ajax,web-services,C#,Jquery,Html,Ajax,Web Services,我在phpstorm中使用bootstrap创建了一个表单html,我想使用ajax将信息传递给c#webservice。 但是我对在ajax url中放置什么有一些疑问(如下面所示) 这是我的html/引导表单: <form role="form" action="" method="post" class="login-form"> <div class="form-group"> <label class="sr-only" for="form-u
<form role="form" action="" method="post" class="login-form">
<div class="form-group">
<label class="sr-only" for="form-username">Email</label>
<input type="text" name="form-username" placeholder="Email....." class="form-username form-control" id="form-email">
</div>
<div class="form-group">
<label class="sr-only" for="form-text">Type Order</label>
<input type="text" name="order" placeholder="Tipo Encomenda" class="form-text form-control" id="textbox1">
</div>
<span id="spnGetdet" style="font-size:x-large" />
<div class="form-group">
<label class="sr-only" for="form-number">Number</label>
<input type="number" min="0" max="150" name="orderQuantity" placeholder="Numero Peças" class="form-number form-control" id="form-number">
</div>
<div class="form-group">
<label class="sr-only" for="form-radio">Urgente</label>
<label class="radio-inline">
<input type="radio" name="optradio">Urgente</label>
<label class="radio-inline">
<input type="radio" name="optradio">Não Urgente
</label>
</div>
<button type="submit" class="btn btn-primary" id="submitOrder">Enviar</button>
</form>
那么,如果我的项目(网站)是在phpstorm和webservice visualstudio中创建的,那么我需要在ajax的url中添加什么才能到达web服务呢
附言:网站运行在xampp中,我假设您使用的是MVC模式,我已经给出了以下url。您应该在[controller]位置替换控制器名称。您应该将[server name]中的localhost:5566或其他内容替换为[server name] 选项1:[获取] 没有数据 选项2:[发布] 使用数据:“{Custname:“Jhon”}” 否则,如果使用Asp.Net模板创建WebMethod,则应使用aspx页面名称代替[controller]
或者,您可以使用路由配置来自定义URL和数据。我们不知道您的Web服务在哪里运行。如何在浏览器中访问它?此外,您的提交处理程序和document.ready都是backwards Web服务是用于在bizagi中运行的,但现在要在浏览器中运行您不需要在click事件处理程序中使用此document ready事件处理程序
$(document).ready(函数(){
什么是控制器?@Adrianomia-我们不知道,这是您的代码和您网站的URL;我们对此没有深入了解。@Markschultheis我只是问控制器在URL中的含义,没有更多,当然您不知道我的代码……但无论如何,谢谢您
<script type="text/javascript">
$("#submitOrder").click(function(){
$(document).ready(function () {
var TextBox1 = $("#textbox1");
TextBox1.change(function (e) {
var Name = TextBox1.val();
if (Name != -1) {
Getdet(Name);
}else {
<?php echo "erro"?>;
}
});
});
}
function Getdet(Name) {
$.ajax({
type: "POST",
url: "",
data: "{'Custname':'" + Name + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response){
$("#spnGetdet").html(response.d);
},
failure: function (msg)
{
alert(msg);
}
});
}
</script>
[WebMethod]
public String GetCustdet(string Custname)
{
return Custname;
}