[英]Drupal node.save and JSONP
I am having an issue with call Drupal node.save using MooTool's JSONP. 我在使用MooTool的JSONP调用Drupal node.save时遇到问题。 Here is an example.
这是一个例子。
Here is my request: 这是我的要求:
callback Request.JSONP.request_map.request_1 回调Request.JSONP.request_map.request_1
method node.save 方法node.save
sessid 123123123123123 sessid 123123123123123
node {"type":"blog","title":"New Title","body":"This is the blog body"} 节点{“ type”:“ blog”,“ title”:“新标题”,“ body”:“这是博客正文”}
Here is my result 这是我的结果
HTTP/1.0 500 Internal Server Error HTTP / 1.0 500内部服务器错误
I got this working before, but i used AMFPHP and was able to send objects to drupal. 我之前可以使用它,但是我使用了AMFPHP并能够将对象发送到drupal。 I am assuming that this has to do with Drupal expecting an object, but since it is a GET it gets transformed as a string.
我假设这与期望对象的Drupal有关,但是由于它是GET,因此将其转换为字符串。 Is there any way of getting around this with out hacking the code?
有什么办法可以解决这些问题而无需修改代码?
Here is my code: 这是我的代码:
$('newBlogSubmit').addEvent('click', function()
{
var node = {
type : "blog",
title:"New Title",
body :"This is the blog body"
}
var string = JSON.encode(node);
string.escapeRegExp()
var sessID = _sessID;
DrupalService.getInstance().node_save(string, sessID, drupal_handleBlogSubmit);
});
My Drupal Service JS Code: 我的Drupal服务JS代码:
//NODE
DrupalService.prototype.node_save = function(node, sessid, callback){
var dataObj = {
method : "node.save",
sessid : sessid,
node : node
}
DrupalService.getInstance().request(dataObj, callback);
}
//SEND REQUEST AND CALLBACK FUNCTION
DrupalService.prototype.request = function(dataObject, callback){
new JsonP('http://myDrupalSite.com/services/json', {data: dataObject,onComplete: callback}).request();
}
I am trying to connect the dots, but not too familiar with Drupal, but i would guess all I need to do is turn the string back into an object. 我试图将点连接起来,但是对Drupal不太熟悉,但是我想我所要做的就是将字符串变成一个对象。 Any ideas where I should be looking, or if there is an existing patch?
有什么想法应该找的,或者是否有现有的补丁?
A first question could be why you use mootools since Drupal comes with jQuery and use it extensively throughout the different modules and Drupal core itself. 第一个问题可能是为什么自jQuery附带Drupal以来,为什么要使用mootools并在不同模块和Drupal核心本身中广泛使用它。
Anyways I don't know mootools so can't help you there, but if your request in ending in a internal server error, you have a problem with your drupal code or your js code. 无论如何,我都不知道mootools是否可以帮助您,但是如果您的请求以内部服务器错误结尾,则您的drupal代码或js代码有问题。 So even if I knew exactly what you were doing, I couldn't tell you the problem without looking at the drupal code for your
http://myDrupalSite.com/services/json
callback. 因此,即使我确切知道您在做什么,如果不查看
http://myDrupalSite.com/services/json
回调的drupal代码,也无法告诉您问题所在。
In general, what you want to make sure is: 通常,您要确保的是:
I've answered a similar question in detail, which was about altering a field instead of saving a node, but much of the work is still the same. 我已经详细回答了一个类似的问题,该问题是关于更改字段而不是保存节点,但是许多工作仍然相同。 You can take a look on the post , although this is with jQuery and not Mootools.
您可以看一下帖子 ,尽管这是使用jQuery而不是Mootools的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.