Parse platform 如何在解析云代码和客户端之间正确传递参数?(httpRequest示例)
我已经看过一些例子,阅读了文档和其他问题,但是我仍然不确定在哪里添加/正确添加要在云代码和客户端之间正确传递的参数 例如,这里我在云代码中从一个httpRequest创建一个新类Parse platform 如何在解析云代码和客户端之间正确传递参数?(httpRequest示例),parse-platform,parameters,httprequest,parameter-passing,parse-cloud-code,Parse Platform,Parameters,Httprequest,Parameter Passing,Parse Cloud Code,我已经看过一些例子,阅读了文档和其他问题,但是我仍然不确定在哪里添加/正确添加要在云代码和客户端之间正确传递的参数 例如,这里我在云代码中从一个httpRequest创建一个新类 Parse.Cloud.run('POSTfromCloud', {}, { success: function(result) { console.log("Posted a new Parse Class from Cloud Code Successfully! :"+ JSO
Parse.Cloud.run('POSTfromCloud', {}, {
success: function(result) {
console.log("Posted a new Parse Class from Cloud Code Successfully! :"+ JSON.stringify(result))
},
error: function(error) {
console.log("Oops! Couldn't POST from Cloud Code successfully.. :"+ error)
}
});
}
var myvalue = "I'm The VALUE";
Parse.Cloud.run('POSTfromCloud', {myValue: myvalue}, {
success: function(result) {
在我的云代码中main.js
Parse.Cloud.define("POSTfromCloud", function(request, response) {
//runs when Parse.Cloud.run("POSTfromCloud") on the client side is called
Parse.Cloud.httpRequest({
method: "POST",
headers: {
"X-Parse-Application-Id": "[PARSE_APP_ID]",
"X-Parse-REST-API-Key": "[PARSE_REST_ID]",
"Content-Type": "application/json"
},
//adds a new class to my parse data
url: "https://api.parse.com/1/classes/newPOSTfromCloudClass/",
body: {
"newPOSTfromCloudClass": {"key1":"value1","key2":"value2"}
},
success: function (httpResponse) {
console.log(httpResponse.text);
response.success(httpResponse);
},
error:function (httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
response.error(httpResponse.status);
}
}); //end of Parse.Cloud.httpRequest()
});
在我的客户方面
Parse.Cloud.run('POSTfromCloud', {}, {
success: function(result) {
console.log("Posted a new Parse Class from Cloud Code Successfully! :"+ JSON.stringify(result))
},
error: function(error) {
console.log("Oops! Couldn't POST from Cloud Code successfully.. :"+ error)
}
});
}
var myvalue = "I'm The VALUE";
Parse.Cloud.run('POSTfromCloud', {myValue: myvalue}, {
success: function(result) {
我的结果:
砰!正确地工作了。现在让我们假设我想让我的url成为传递的许多参数之一,我该怎么做 当我问这个问题时,我也在修补一些东西,因为我不能正确地传递任何东西(或者它将作为空值返回),所以这里我有一个示例,说明如何将参数传递到这个函数中 在my cloudcode main.js中
Parse.Cloud.define("POSTfromCloud", function(request, response) {
//HERE- make a new instance of 'myValue' for Cloudcode to handle
var myValue = request.params.myValue;
Parse.Cloud.httpRequest({
method: "POST",
....[blah blah]
//AND HERE- placed that here in my body, **note:** you shouldnt store tokens like this, ignore what I named it
body: {
"newPOSTfromCloudClass": {"yourToken":myValue,"key2":"value2"}
},
客户端
Parse.Cloud.run('POSTfromCloud', {}, {
success: function(result) {
console.log("Posted a new Parse Class from Cloud Code Successfully! :"+ JSON.stringify(result))
},
error: function(error) {
console.log("Oops! Couldn't POST from Cloud Code successfully.. :"+ error)
}
});
}
var myvalue = "I'm The VALUE";
Parse.Cloud.run('POSTfromCloud', {myValue: myvalue}, {
success: function(result) {
结果:这应该正确传递参数。再次忽略我使用的标题“yourToken”,你不应该像那样存储令牌
这花了一段时间来整理,我希望这能帮助一些人。当我问这个问题时,我也在修补一些东西,因为我不能正确地传递任何东西(或者它会返回为空值),所以这里我有一个示例,说明了如何将参数传递到这个函数中 在my cloudcode main.js中
Parse.Cloud.define("POSTfromCloud", function(request, response) {
//HERE- make a new instance of 'myValue' for Cloudcode to handle
var myValue = request.params.myValue;
Parse.Cloud.httpRequest({
method: "POST",
....[blah blah]
//AND HERE- placed that here in my body, **note:** you shouldnt store tokens like this, ignore what I named it
body: {
"newPOSTfromCloudClass": {"yourToken":myValue,"key2":"value2"}
},
客户端
Parse.Cloud.run('POSTfromCloud', {}, {
success: function(result) {
console.log("Posted a new Parse Class from Cloud Code Successfully! :"+ JSON.stringify(result))
},
error: function(error) {
console.log("Oops! Couldn't POST from Cloud Code successfully.. :"+ error)
}
});
}
var myvalue = "I'm The VALUE";
Parse.Cloud.run('POSTfromCloud', {myValue: myvalue}, {
success: function(result) {
结果:这应该正确传递参数。再次忽略我使用的标题“yourToken”,你不应该像那样存储令牌
这需要一段时间来整理,我希望这可以帮助别人