mercredi 13 janvier 2016

Javascript Web API JSON Parsing Format issue

Hi i have an issue with a few lines of code in JS and formatting my JSON data. Basically in my DB i have a field that is set to nchar(10) but some of the data in the fields are for example only 8 characters long.

The problem i have is when my JS generates a link from JSON data it attaches Spaces to the Data to compensate the (10) characters. For example clicking a link generated from the JS Would generate a link for me like this http://....api/Repo/rep10016

In my JSON it passes in this data rep10016

But my JS is grabbing this data for the link adding spaces up to 10 as it is a nchar(10) like this.

repoCode = "rep10016  "

But i only want

repoCode = "rep10016"

My JS Code

function displayRepos(repo) {

    var table = document.getElementByrCode("rList");       
    table.innerHTML = "";       
    for (var i = 0; i < arr.length; i++) 
    {            
        var rCode = arr[i].repoCode;
        cell2.innerHTML = "<a href='#'rCode='" + rCode + "' " + " >Repo List</a>";
        document.getElementByrCode(rCode).onclick = getRepo;
    }


    function getRepo(rep) 
    {        
    var repoUrl = genUrl+rep.target.rCode+"?code="+rep.target.rCode;
    ......
    }

The repoUrl variable is generating a link like this

"http://....api/Repo/rep10016  ?code=rep10016  /"

How can i get my code to only take the actual data and not format it to the nchar(10) format that is in my db??




Aucun commentaire:

Enregistrer un commentaire