Parameter arriving truncated in Ajax request

1

I have a Ajax request that gets the data I need from a WebMethod . The problem is that the parameter used for the request is "arriving" truncated in WebMethod the length of the parameter is 44 digits.

Parameter sent: 31161102996615000145550000000413281487877818 .

How's it coming: 3.1161102996615E+43

Ajax code:

var valorCampo= $(this).attr('data-clipboard-text');
var content = "parametroConsulta=" + encodeURIComponent(valorCampo);

$.ajax({

        type: "GET",
        dataType: 'json',
        async: false,
        contentType: "application/json; charset=utf-8",
        url: "myPage.aspx/ObtenhaDados",
        data: content,
        success: function (data) { dadosObtidos(data); },
        error: function (data) { falhaConsulta(data); }

});

WebMethod :

 [WebMethod]
 [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
 public static DadosPessoais ObtenhaDados(string valoPesquisa)
 { .... }

Url displayed in FireBug:

http://localhost:61187/ps/myPage.aspx/ObtenhaDados?valoPesquisa=31161102996615000145550000000413281487877818

    
asked by anonymous 22.11.2016 / 11:42

2 answers

1

I was able to solve the problem by putting the parameter between "'". Code below:

var valorCampo = $(this).attr('data-clipboard-text');
var content = {valorPesquisa: "'" + valorCampo + "'"};
    
22.11.2016 / 15:53
0

This will pass the value as a string and concatenate with the Query parameter, but you could do this in C #

var valorCampo= $(this).attr('data-clipboard-text');
var content = "parametroConsulta=" + valorCampo.toString();

$.ajax({

        type: "GET",
        dataType: 'json',
        async: false,
        contentType: "application/json; charset=utf-8",
        url: "myPage.aspx/ObtenhaDados",
        data: content,
        success: function (data) { dadosObtidos(data); },
        error: function (data) { falhaConsulta(data); }

});
    
22.11.2016 / 13:48