当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net - Not able to retrieve if the parameter starts with zero when passing from jquery to my webmethod

问题描述:

My Problem looks really strange, I am calling an Autocomplete.asmx web method from jQuery. Thew first time the first parameter, 0, is passing, and the second time the zero is getting replaced, instead of 0, any other numbers are getting displayed.

Aspx:

 function SearchText() {

$('#<%=txtphoneno.ClientID%>').autocomplete({

source: function (request, response) {

Search();

}

});

}

//-->loadtop 5 jobs

function Search() {

var callid = $('#<%= txtphoneno.ClientID%>').val().toString();

// alert(callid);

$.ajax({

type: "POST",

contentType: "application/json; charset=utf-8",

url: "../HttpHandler/Autocomplete.asmx/GetCallername",

data: "{'callerid':" + callid + "}",

dataType: "json",

success: function (data) {

//response(data.d);

// alert(data.d);

$('#<%=txtname .ClientID %>').removeClass('text-label');

$('#<%=txtname .ClientID %>').addClass('lbls');

$('#<%=txtnote .ClientID %>').removeClass('text-label');

$('#<%=txtnote .ClientID %>').addClass('lbls');

document.getElementById('<%=txtname .ClientID %>').value = data.d[0];

document.getElementById('<%=txtnote .ClientID %>').value = data.d[1];

if (data.d != 'User Doesnt Exist') {

var param = $('#<%= txtphoneno.ClientID%>').val();

$("#<%=IframeJobHistory.ClientID%>").show();

LoadHistoryDetails(param);

}

else {

// $("#<%=IframeJobHistory.ClientID%>").hide();

}

},

error: function (result) {

// alert("Error");

}

});

}

** CS Code AutoComplete.Asmx**

[WebMethod ]

public string [] GetCallername(String callerid)

{

..............................

return CallerDetails;

}

}

In the String callerid, the first time when the user enters 0 I am getting back 0, but second time when the user enters any number I am getting the number but the Zero disappears.

If i use any other number,apart from zero things are working fine.

网友答案:

instead of using zero try to use -1

网友答案:

Sorry , I don't know what you missed , But I know the simple one solution for your issue .

Just add this code for dynamically add 0 if the first value is not zero, Otherwise it's diaplayed your default value

Put break point and check

    [WebMethod ]    
    public string [] GetCallername(string callerid)
    {
       string Filteredcallerid = !string.IsNullOrEmpty(callerid) ? callerid.Substring(0, 1) : "";
       callerid = Filteredcallerid != "0" ? "0" + callerid : callerid;
       return CallerDetails;

    }
分享给朋友:
您可能感兴趣的文章:
随机阅读: