如何将json字符串解析为整数? (ajax)

时间:2018-12-04 06:19:41

标签: json ajax api

我对这些代码有疑问。

<script>
$(function() {
    $('#submitRegister').click(function (e) {
        console.log('jalan fungsi submit');
        e.preventDefault();
        var paramObj = {};
        $.each($('#registerForm').serializeArray(), function (_, kv) {
            if (paramObj.hasOwnProperty(kv.name)) {
                paramObj[kv.name] = $.makeArray(paramObj[kv.name]);
                paramObj[kv.name].push(kv.value);
            }
            else {
                paramObj[kv.name] = kv.value;
            }
        });
        console.log(paramObj);

        var dataMitra = paramObj;
        var urlAjax = "my url";

        $.ajax({
            type: "POST",
            url: urlAjax,
            contentType: "application/json; charset=utf-8",
            data: dataMitra,
            crossDomain: true,
            success: function (data) { alert("ajax worked"); },
            error: function (data) { console.log(data); },
            dataType: "json",
            beforeSend: function (xhr) {
                xhr.setRequestHeader("content-type", "application/json");
                xhr.setRequestHeader("accept", "application/json");
            },
            headers: {
                'Access-Control-Allow-Origin': '*'
            }
        });
    });
});

使用ajax发布到我的API,使用整数需要几个字段。在下面看起来是json

================================================ =

ada_lahan: "1" *
alamat_juragan: "jalan intan v no. 192"
alamat_lahan: ""
code: "10640" *
country_id: "100" *
email: "gecok123@gmail.com"
juragan: "arjuna"
juragan_refferal: "1" (it should be int)
juragan_stage: "arjuna"
kabupaten_id: "2" *
kecamatan_id: "2" *
kelurahan_id: "4" *
lahan_kabupaten_id: "Kota / Kab*"
latitude_juragan: "-6.1642709" *
longitude_juragan: "106.86704039999995" *
nama_juragan: "bram story"
provinsi_id: "27" *
telepon: "82312233332"

================================================ ==

注意:*表示应为整数值

我如何将字符串值解析为整数?仅适用于几个领域。 谢谢

0 个答案:

没有答案