无法使用参数调用WebMthod [英] Could not call a WebMthod with parameters
问题描述
这是我的主题的开发延续
使用JQuery从WebMethod获取数据 [ ^ ]
在上一个场景中,我创建了一个WebMethod GetData()。下面的代码工作正常
< button id = submitButton data-dojo-type = dijit.form.Button数据 - dojo-props = onClick:function(){
var e = document.getElementById('routeID') ;
var routeById = e.options [e.selectedIndex] .text;
var mA = document.getElementById('MeasureA')。value;
var mB = document.getElementById('MeasureB ')。value;
调试器;
$ .support.cors = true;
var ajaxData;
$ .ajax({
类型:'获取',
url:'SOEDefault.aspx / GetData()',
dataType:'text',
data:'{}',
contentType:'application / json; charset = utf -8',
crossDomain:true,
success:function(results){
console.log('Success!');
调试器;
ajaxData = results;
},
错误:函数(xhr,状态,错误){
debugger;
console.log(错误);
}
});
...
现在我为GetData添加了三个参数(routeID,mA,mB)' 。 3个参数是文本框或下拉列表中的值。我还在.aspx.cs中修改了带有3个参数的GetData方法。但是,当我单击按钮时,我收到内部服务器错误。请告诉我我的JavaScript代码有什么问题。谢谢。
.support.cors = true;
var ajaxData;
.ajax({
type:'Get',
url:'SOEDefault.aspx / GetData()',
dataType:'text',
data:'{}',
contentType:'application / json; charset = utf-8',
crossDomain:true,
success :function(results){
console.log('Success!');
debugger;
ajaxData = results;
},
error:function(xhr,状态,错误){
调试器;
console.log(错误);
}
});...
现在我为GetData(routeID,mA,mB)添加了三个参数。 3个参数是文本框或下拉列表中的值。我还在.aspx.cs中修改了带有3个参数的GetData方法。但是,当我单击按钮时,我收到内部服务器错误。请告诉我我的JavaScript代码有什么问题。谢谢。
您实际上并没有向ajax调用提供任何数据。您需要将dataType
设置为json
而不是text
,并将数据设置为:data: JSON .stringify({routeID:routeById,mA:mA,mB:mB}),
This is the development continuation of my thread
Get Data from WebMethod Using JQuery[^]
In previous scenario, I created a WebMethod GetData(). The code below works fine
<button id="submitButton" data-dojo-type="dijit.form.Button" data-dojo-props="onClick:function(){
var e = document.getElementById('routeID');
var routeById = e.options[e.selectedIndex].text;
var mA = document.getElementById('MeasureA').value;
var mB = document.getElementById('MeasureB').value;
debugger;
$.support.cors = true;
var ajaxData;
$.ajax( {
type:'Get',
url: 'SOEDefault.aspx/GetData()',
dataType: 'text',
data: '{}',
contentType: 'application/json; charset=utf-8',
crossDomain : true,
success:function(results) {
console.log('Success!');
debugger;
ajaxData = results;
},
error: function(xhr, status, error) {
debugger;
console.log(error);
}
});
...
Now I added three parameters for the GetData(routeID, mA, mB)'. The 3 parameters are the values from textboxes or dropdownlist. I also revised the GetData methods with 3 parameters in .aspx.cs. However, when I click the button, I got "Internal Server Error". Please advise me what's wrong in my JavaScript code. Thanks.
.support.cors = true; var ajaxData;
.ajax( { type:'Get', url: 'SOEDefault.aspx/GetData()', dataType: 'text', data: '{}', contentType: 'application/json; charset=utf-8', crossDomain : true, success:function(results) { console.log('Success!'); debugger; ajaxData = results; }, error: function(xhr, status, error) { debugger; console.log(error); } });...
Now I added three parameters for the GetData(routeID, mA, mB)'. The 3 parameters are the values from textboxes or dropdownlist. I also revised the GetData methods with 3 parameters in .aspx.cs. However, when I click the button, I got "Internal Server Error". Please advise me what's wrong in my JavaScript code. Thanks.
You aren't actually supplying any data to the ajax call. You need to set yourdataType
tojson
rather thantext
, and set data as:data: JSON.stringify({routeID: routeById, mA: mA, mB: mB}),
这篇关于无法使用参数调用WebMthod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!