Javascript 使用reactive.js将JSON数据/对象发布到API

Javascript 使用reactive.js将JSON数据/对象发布到API,javascript,arrays,json,Javascript,Arrays,Json,我试图使用ractive.js将JSON数据/对象添加到API中,但没有得到任何结果。它向我显示了一个回答“没有内容”。不确定我目前缺少什么。我正在为这个项目使用racive.js 这是我一直在编写的示例代码 app.on('addLead', function() { var proxy = app.get('proxy'); var endpoint = 'account/leads/'; var rt = 'POST';

我试图使用ractive.js将JSON数据/对象添加到API中,但没有得到任何结果。它向我显示了一个回答“没有内容”。不确定我目前缺少什么。我正在为这个项目使用racive.js

这是我一直在编写的示例代码

app.on('addLead', function() {
    var proxy        = app.get('proxy');
    var endpoint     = 'account/leads/';
    var rt           = 'POST';
    var url          = proxy+'?endpoint='+endpoint+'&rt='+rt;
    var data         = {
        "isProfiled": true,
        "isBaluarte": 0,
        "isVertical": 0,
        "isAffiliate": 0,
        "isBranch": 0,
        "id": 0,
        "dateRequested": "2017-01-12T07:13:19.717Z",
        "accountIdFk": 0,
        "accountLeadId": 1285689131,
        "accountName": "Noel String",
        "assignedEmployeeIdFk": 0,
        "unitNumber": "string",
        "floorNumber": "string",
        "buildingName": "string",
        "streetNumber": "string",
        "streetName": "string",
        "barangayIdFk": 0,
        "cityTownIdFk": 0,
        "provinceIdFk": 0,
        "regionIdFk": 0,
        "leadsIdentifier": "string",
        "salesRegion": "string",
        "egApproval": "string",
        "smsId": "string",
        "dateComSmsId": "2017-01-12T07:13:19.717Z",
        "egRemarks": "string",
        "dateComGbuTag": "2017-01-12T07:13:19.717Z",
        "sgRemarks": "string",
        "taggingDetailsIdFk": 0,
        "profiling": "string",
        "dateCompletedGbuTag": "2017-01-12T07:13:19.717Z",
        "gbuTagidFk": 0,
        "longitude": 0,
        "latitude": 0,
        "numberOfEmployees": "string",
        "tier": "string",
        "industryTypeIdFk": 0,
        "gbuMigration": "string",
        "finalReco": "string",
        "motherAccountId": 0,
        "remarksFindings": "string",
        "finalCompanyName": "string",
        "accountCategoryIdFk": 0,
        "sourceLeadIdFk": 0,
        "baluarte": true,
        "vertical": true,
        "affiliate": true,
        "branch": true,
        "profiled": true
    };

    $.ajax({
         type    : 'POST',
         url     : url,
         data    : data,
         success : alert('success')
    });
    console.log(data);
});
Chrome工具开发网络

概述

Request URL:http://192.168.1.126/lms-dev-noel/proxy.php?endpoint=account/leads/&rt=POST
Request Method:POST
Status Code:200 OK
Remote Address:192.168.1.126:80
Response Headers
view source
Access-Control-Allow-Origin:*
Connection:Keep-Alive
Content-Length:841
Content-Type:text/json
Date:Fri, 13 Jan 2017 02:52:16 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.7 (Ubuntu)
X-Powered-By:PHP/5.5.9-1ubuntu4.20
请求标题

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:934
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:__atuvc=3%7C51%2C1%7C1; SESSfb2f81a034926ea9559505bfadcce9a3=RcchjmRlh0jHPn4LuTES7YMkAHnKbsotRdHIo2Gtbqw; SESS2b177789a8b29da818933ad27543b7ad=zjWnvbr75ZMuZMnwVXCb6PGkRzg8eTP0C2dCeaBZ9Sw; _ga=GA1.1.1071659288.1482134344
Host:192.168.1.126
Origin:http://192.168.1.126
Referer:http://192.168.1.126/lms-dev-noel/site/
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
X-Requested-With:XMLHttpRequest
endpoint:account/leads/
rt:POST
Form Data
view source
view URL encoded
isProfiled:true
isBaluarte:0
isVertical:0
isAffiliate:0
isBranch:0
id:0
dateRequested:2017-01-12T07:13:19.717Z
accountIdFk:0
accountLeadId:1285689131
accountName:Noel String
assignedEmployeeIdFk:0
unitNumber:string
floorNumber:string
buildingName:string
streetNumber:string
streetName:string
barangayIdFk:0
cityTownIdFk:0
provinceIdFk:0
regionIdFk:0
leadsIdentifier:string
salesRegion:string
egApproval:string
smsId:string
dateComSmsId:2017-01-12T07:13:19.717Z
egRemarks:string
dateComGbuTag:2017-01-12T07:13:19.717Z
sgRemarks:string
taggingDetailsIdFk:0
profiling:string
dateCompletedGbuTag:2017-01-12T07:13:19.717Z
gbuTagidFk:0
longitude:0
latitude:0
numberOfEmployees:string
tier:string
industryTypeIdFk:0
gbuMigration:string
finalReco:string
motherAccountId:0
remarksFindings:string
finalCompanyName:string
accountCategoryIdFk:0
sourceLeadIdFk:0
baluarte:true
vertical:true
affiliate:true
branch:true
profiled:true
查询字符串参数

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:934
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:__atuvc=3%7C51%2C1%7C1; SESSfb2f81a034926ea9559505bfadcce9a3=RcchjmRlh0jHPn4LuTES7YMkAHnKbsotRdHIo2Gtbqw; SESS2b177789a8b29da818933ad27543b7ad=zjWnvbr75ZMuZMnwVXCb6PGkRzg8eTP0C2dCeaBZ9Sw; _ga=GA1.1.1071659288.1482134344
Host:192.168.1.126
Origin:http://192.168.1.126
Referer:http://192.168.1.126/lms-dev-noel/site/
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
X-Requested-With:XMLHttpRequest
endpoint:account/leads/
rt:POST
Form Data
view source
view URL encoded
isProfiled:true
isBaluarte:0
isVertical:0
isAffiliate:0
isBranch:0
id:0
dateRequested:2017-01-12T07:13:19.717Z
accountIdFk:0
accountLeadId:1285689131
accountName:Noel String
assignedEmployeeIdFk:0
unitNumber:string
floorNumber:string
buildingName:string
streetNumber:string
streetName:string
barangayIdFk:0
cityTownIdFk:0
provinceIdFk:0
regionIdFk:0
leadsIdentifier:string
salesRegion:string
egApproval:string
smsId:string
dateComSmsId:2017-01-12T07:13:19.717Z
egRemarks:string
dateComGbuTag:2017-01-12T07:13:19.717Z
sgRemarks:string
taggingDetailsIdFk:0
profiling:string
dateCompletedGbuTag:2017-01-12T07:13:19.717Z
gbuTagidFk:0
longitude:0
latitude:0
numberOfEmployees:string
tier:string
industryTypeIdFk:0
gbuMigration:string
finalReco:string
motherAccountId:0
remarksFindings:string
finalCompanyName:string
accountCategoryIdFk:0
sourceLeadIdFk:0
baluarte:true
vertical:true
affiliate:true
branch:true
profiled:true

您需要使用
JSON.stringify()

JSON.stringify函数将Javascript对象转换为JSON文本并存储在字符串中。

在服务器端,您必须
解析
字符串

参见参考文献


您的url似乎是错误的:
proxy+'?endpoint'+endpoint+'&rt='+rt。请更改为:
proxy+'?endpoint='+endpoint+'&rt='+rt。您在
端点之后忘记了
=
。我在控制台上没有收到任何错误,并且在您指出它影响您的方法之前我已经更改了URL?您的
数据是一个对象。为了传递到服务器端,您需要使用
JSON.stringify
data:JSON.stringify(data)
我尝试了那个解决方案,结果还是一样的。它向我显示了一个回答“无内容”