简体   繁体   中英

Code-generated input in Google Chrome DevTools Console

I am trying to read card data using MagTek card reader through MagTek Web API. The code which is used for this

...
function doRequest(url, data, timeout, success, handleError) {
    var request = {
        url: HTTP_HOST + path,
        method: method,
        data: data,
        headers: {
            'Content-Type': 'application/json; charset=UTF-8',
            'Cache-Control': 'no-cache'
        },
        dataType: 'json',
        success: success,
        timeout: timeout,
        error: handleError
    };
    $.ajax(request);
}
...


function extractCardDataFromResponse(response) {
    var data = response.CardSwipeOutput;
    var names = data.CardName.split('/');
    return {
        cardNumber: data.Track2Masked.split('=')[0].substr(1),
        lastName: names[0],
        firstName: names[1],
        expirationMonth: data.CardExpDate.substr(-2),
        expirationYear: '20' + data.CardExpDate.substr(0, 2),
        track2: data.Track2,
        dukptksn: data.KSN
    };
}

function readCard(handlerCardData, onReady, onError) {
    try {
        ...
        onReady();
        ...
        doPost('/RequestCardSwipe', requestBody, 300000, function (response) {
            if (response.CardSwipeOutput.TrackDecodeStatus === '000000') {
                handlerCardData(extractCardDataFromResponse(response));
            }
        }, onError);
    } catch (e) {
        onError(e);
    }
}

I run readCard((a)=>console.log(a), ()=>console.log('ready'), (e)=> {console.log('error');console.log(e);}) in Chrome Developers Console. After swipe the card data is inserted into console. Why such thing may happen?

在此处输入图片说明

MagTek's card readers can be set to one of two modes, HID mode, or KB Emulation mode. In my case card reader was in Key board Emulation mode and card data was inserted to Chrome console. When I set reader to HID mode it started working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM