警报框中的数据通过函数javascript [英] data in alert box through function javascript
问题描述
参考这个问题,这是如何解决这个问题的没有功能。
现在我有一个函数,我尝试在JavaScript中调用,并尝试在 alert
框中调用该数据,但是 alert code>框不填充。我的代码是这样的:
< script type =text / javasc riptsrc =https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js>< / script>< form id =form1runat =server > < asp:DropDownList ID =yearValuerunat =serverAutoPostBack =TrueViewStateMode =Enabled>< / asp:DropDownList> < button id =submitchartrunat =server>显示图表< / button> < div id =containerstyle =width:100%; height:400px;>< / div>< / form>
< title>< / title>
< script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js>< / script>
< / head>
< body>
< form id =form1runat =server>
< button id =submitchartrunat =servertype =button>显示图表< / button>
< div id =containerstyle =width:100%; height:400px;>< / div>
< / form>
< / body>
< script type =text / javascript>
$('#submitchart')。click(function(){
// alert(i);
var webmethod ='test.php';
$。 ajax({
type:'POST',
url:webmethod,
data:JSON.stringify({
yearP:$('#yearValue')。val()
}),
contentType:'application / json; charset = utf-8',
dataType:'json',
成功:函数(响应){
alert ('working');
},
错误:function(){
alert('error');
}
});
});
函数Loadchart(){
$('#submitchart')。click();
};
< / script>
以上代码正在运行。检查并更新你的。确保按钮类型按钮。
With reference of this question, this is how solved this without a function.
Now I have a function and I try to call in javascript and also try to call that data in alert
box but the alert
box does not populate. My code is this:
$('#submitchart').click(function() {
//alert("i");
var webmethod = 'WebForm1.aspx/Jqufunc';
$.ajax({
type: 'POST',
url: webmethod,
data: JSON.stringify({
yearP: $('#yearValue').val()
}),
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success: function(response) {
debugger;
alert(JSON.stringify(response.d));
var data1 = response.d.split('*')[0];
var data2 = response.d.split('*')[1];
alert(data1);
alert(data2);
},
error: function() {
debugger;
alert(data1);
alert(data2);
}
});
});
function Loadchart() {
$('#submitchart').click();
};
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<form id="form1" runat="server">
<asp:DropDownList ID="yearValue" runat="server" AutoPostBack="True" ViewStateMode="Enabled"></asp:DropDownList>
<button id="submitchart" runat="server">Show Chart</button>
<div id="container" style="width: 100%; height: 400px;"></div>
</form>
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<select id="yearValue"><option>1920</option></select>
<button id="submitchart" runat="server" type="button">Show Chart</button>
<div id="container" style="width: 100%; height: 400px;"></div>
</form>
</body>
<script type="text/javascript">
$('#submitchart').click(function () {
//alert("i");
var webmethod = 'test.php';
$.ajax({
type: 'POST',
url: webmethod ,
data: JSON.stringify({
yearP: $('#yearValue').val()
}),
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success: function(response) {
alert('working');
},
error: function () {
alert('error');
}
});
});
function Loadchart() {
$('#submitchart').click();
};
</script>
Above code is working. Check and update with yours. Make sure button type button.
这篇关于警报框中的数据通过函数javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!