简体   繁体   中英

How to make post request using javascript

I am trying to make a POST request in javascript. But response is not getting.

http://xecutehr.com/api/HRMSService.svc/PostAttendance?input={"Header":{"CompanyId":"MTF","LicenceKey":"MTF-4525"},"Body":{"E_Code":"01330","AttendanceDateTime":"2016-04-27T13:00:30","Mode":"I","DeviceId":"MTF1330"}}

This is the url format and this is the code I have written:

if(valid){
    var values    = form.serializeObject();
    var e_code    = values.staff_code.substring(3);
    var device_id = values.staff_code;
    var date_time = datetime;
    var url       = "http://xecutehr.com/api/HRMSService.svc/PostAttendance?input=";
    $.ajax({
        url:url,
        headers: {
            "CompanyId":"MTF",
            "LicenceKey":"MTF-160427-RHGB-4525"
        },
        type: "POST",
        data:{
            "E_Code":"0"+e_code,
            "AttendanceDateTime":date_time,
            "Mode":"I",
            "DeviceId":device_id
        },
        datatype: "jsonp",
        success: function(data) {
            alert(response); 
        }
    });
}

I tried a lot I am missing some basics in in . How can I handle this? suggest some solutions or links

You can't have jsonp and do a POST.

A jsonp request loads as a <script> .

Eg

request: /url?callback=something&E_Code=0something

The response will be something like:

something({E_Code: '0something'})

Where something() is your ajax response handler.

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