I have a stored procedure with an optional parameter like this:
CREATE PROCEDURE SP_GetPData
(@StDt Datetime,
@EndDt Datetime,
@Process VARCHAR(10) = NULL,
@Item VARCHAR(50) = NULL)
Then I have a method in my web service ( .asmx
) file like this:
public string GetProdData(string stdt, string enddt, [Optional] string process, [Optional] string item)
{
return (ConvertDataToJsonString(result));
}
I call this method from my webpage like below:
var params = new Object();
params.stdt = myStDt;
params.enddt = myEndDt;
params.process = ??;
params.item = ??;
$.ajax ( {
url: /myWebService.asmx/GetProdData
,data:JSON.stringify(params);
,success:function(response){}
,error:function(response){} } );
How to pass the optional parameter through Ajax, or is there any way to get result with full parameters or by not providing optional parameters?
Do I need to refine the web service method or any other way out...
1条答案
按热度按时间w9apscun1#
I manage to achieve this by changing my WebService(.asmx) method as follows.
And in FrontEnd (Page Level)Javascript/JQuery as follows: