ChemDoodle Ajax Incompatibility with Pollen.js

天大地大妈咪最大 提交于 2019-12-25 03:54:14

问题


I'm trying to use iChemLabs cloud services from a html5 web worker. Normally the cloudservices requires jQuery but I can't import that into a web worker so I'm using Pollen instead with a ChemDoodle Web Components library with which I have stripped out the document-related things.

jQuery.Hive.Pollen provides a nice ajax function very similar to jQuery, but I can't seem to get it to work at all. I know this problem will be tricky to solve considering that Access-control-headers need to be set to allow any of you to actually find the solution. However, I'm a beginning javascript programmer and I was wondering if my two weeks of frustration is actually a small difference. I am trying to invoke the following function:

var cloudmolecule;

ChemDoodle.iChemLabs.readSMILES('N1(C)C(=O)N(C)C(C(=C1N1)N(C=1)C)=O', function(mol){
    cloudmolecule = mol;
});

Here is a link to the library code I am using, see the 'q.ajax' call and substitute jQuery = q for p = q (p is for pollen) in that block of code.

Right now I'm just trying to get the ajax call to work in an ordinary block of javascript with the plan to migrate to a web worker later.

If anybody could point out the problem to me I would be extremely grateful.


回答1:


solved! turns out iChemLabs rejects these two extra headers that pollen creates:

_xhr.setRequestHeader("X-Requested-With", "Worker-XMLHttpRequest");
_xhr.setRequestHeader("X-Worker-Hive", "Pollen-JS" );

Simply comment them out

Also, Pollen ajax seems to return a JSON object containing the data in JSON format AND as a string, so do

o = JSON.parse(data.string)//data is the parameter to the callback function

The reduced ChemDoodle library (without document-related methods) will work like a charm with pollen ajax.



来源:https://stackoverflow.com/questions/7327894/chemdoodle-ajax-incompatibility-with-pollen-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!