Url = '' ;
POSTDATAS = {};

function doRealRequest(){
    $.ajax({
        type: 'POST',
        url: Url,
        data: POSTDATAS,
        success: function(retdata){
            $("#ret").html(JSON.stringify(retdata));
        },
        dataType: 'json'
    });
}

function  getUrl(parobj){
    const locationHost = 'http://' + window.location.host + '/Inapi-index/makeurl';
    $.ajax({
        type: 'POST',
        url: locationHost,
        data: parobj,
        success: function(returndatas){

            if (returndatas.status!=1){
                alert('发生错误：'+returndatas.msg);
                return ;
            }
            Url = returndatas.data.url;
            doRealRequest();
        },
        dataType: 'json'
    });
}

function  subForm(){
       var ParasObj = {};
       var Mitems = $(".fitem");
       var len  = Mitems.length ;
       for (var i=0 ; i<len ;i++){
           var name = $(Mitems[i]).attr('name');
           var val = $(Mitems[i]).val() ;
           ParasObj[name] = val ;
       }
       ParasObj['debug']=1 ;
       POSTDATAS = ParasObj;

       $("#ret").html('');
       $("#paras").html(JSON.stringify(ParasObj));

       getUrl(ParasObj);
}

$(document).ready(function(){
    $("#mbutton").on("click", function(){
        subForm();
    });
});


