jquery 传递参数调用webservice

wenyiyi 2018-02-01 11:09:56
页面中 有个日期控件, 通过点击按钮将参数传递给 webservcie 方法,返回结果。
现在如果是 data: { user_id: '', date: '' } 则能返回值
如果 将参数改为变量形式 data: {user_id: '',date: today },就不能返回结果


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoadDataWeb.aspx.cs" Inherits="Enterprise_LoadDataWeb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">

</head>
<body>
<form id="form1" runat="server">
<div>



</div>
</body>
<body onload="FormatDate()">
<div>
<%-- <input type="text" id="example" />--%>
<label for="meeting">销售日期:</label><input id="meeting" type="date" value="FormatDate()"/>

<script type="text/javascript">
var today
function FormatDate()
{
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
today = now.getFullYear() + "-" + (month) + "-" + (day);
$('#meeting').val(today);


}

function load() {
//alert(document.getElementById("meeting").value);
//alert(today);

jQuery.ajax({

type: "get",
cache: false,
async: false,
url: "http://wenyiyi.top:22346/WebServiceOOVV.asmx/ReturnShopSaleInfo_UserAndDay ",
dataType: 'text',
data: {user_id: '',date: today },
success: function (jsonData) {
var json = eval("(" + jsonData + ")");
$.each(json, function (index, item) {
alert(today);
var name = json[index].name;
var shop_id = json[index].shop_id;
var shop_name = json[index].shop_name;
var area_val = json[index].area_val;
var salemoney = json[index].salemoney;
var salecount = json[index].salecount;

//var x = document.getElementById("list")
//x.remove(x.selectedIndex)


//$("#list").html() + "<tr><td class='admincls0'>" + shop_name + "</td><td class='admincls0'>" + shop_id + "</td><td class='admincls0'>" + area_val + "</td><td class='admincls0'>" + salemoney + "</td><td class='admincls0'>" + salecount + "</td></tr>";
$("#list").html($("#list").html() + "<tr><td class='admincls0'>" + shop_name + "</td><td class='admincls0'>" + shop_id + "</td><td class='admincls0'>" + area_val + "</td><td class='admincls0'>" + salemoney + "</td><td class='admincls0'>" + salecount + "</td></tr>");

});

},
error: function () {
alert('error!');
}
});






}

</script>

<script type="text/javascript">
$(function () {
$(location).attr('href', '/LoadDataWeb.aspx?code=' +<%=user_id%> +"&querydate="+<%=querydate%>);
});
</script>

<input id="Button1" type="button" value="button" onclick="load()" /><table class="admintable" width="100%">
<thead>
<tr>

<th class="adminth">门店名称</th>
<th class="adminth">门店编号</th>
<th class="adminth">区域</th>
<th class="adminth">销售金额</th>
<th class="adminth">销售数量</th>

</tr>
</thead>
<tbody id=list></tbody>
</table>
</div>
</body>
</form>
<script src="../Js/jquery-1.7.2.min.js"></script>
<script>



$(document).ready(function(){
jQuery.ajax({

type: "get",
cache: false,
async: false,
url: "http://wenyiyi.top:22346/WebServiceOOVV.asmx/ReturnShopSaleInfo_UserAndDay ",
dataType: 'text',
//data: { user_id: '<%=user_id%>', date: '' },
data: { user_id: '', date: '' },
success: function (jsonData) {
var json = eval("("+jsonData+")");

$.each(json, function (index, item) {

var name = json[index].name;
var shop_id = json[index].shop_id;
var shop_name = json[index].shop_name;
var area_val = json[index].area_val;
var salemoney = json[index].salemoney;
var salecount = json[index].salecount;

$("#list").html($("#list").html() + "<tr><td class='admincls0'>" + shop_name + "</td><td class='admincls0'>" + shop_id + "</td><td class='admincls0'>" + area_val + "</td><td class='admincls0'>" + salemoney + "</td><td class='admincls0'>" + salecount + "</td></tr>");

});

},
error: function () {
alert('error!');
}
});
});



</script>
</html>

...全文
500 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenyiyi 2018-02-03
  • 打赏
  • 举报
回复
解决问题了。赋值的问题。
wenyiyi 2018-02-02
  • 打赏
  • 举报
回复
顶上去!有谁知道吗?
wenyiyi 2018-02-02
  • 打赏
  • 举报
回复
@天际的海浪 已经执行,都能在alert中捕捉到值
wenyiyi 2018-02-02
  • 打赏
  • 举报
回复
已经执行了。 //alert(document.getElementById("meeting").value); 这处已经捕捉到值了
天际的海浪 2018-02-02
  • 打赏
  • 举报
回复
先确定load函数执行前FormatDate函数已经执行
wenyiyi 2018-02-02
  • 打赏
  • 举报
回复
谁能帮我看下这个问题出在那啊?

52,798

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧