2010-04-05 41 views
1

我想要的是获取正确的参数,如果您看到参数已记录,那么您可以告诉我问题是否存在我的JavaScript?AJAX发布请求,包含数组和其他对象的对象无法正确解析为导轨

首先运行runMe功能

Ajax: function() 
{ 
    var xmlhttp, bComplete = false; 
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
    catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
    catch (e) { try { xmlhttp = new XMLHttpRequest(); } 
    catch (e) { xmlhttp = false; }}} 
    if (!xmlhttp) return null; 
    this.connect = function(sURL, sMethod, sVars, fnDone) 
    { 
    if (!xmlhttp) return false; 
    bComplete = false; 
    sMethod = sMethod.toUpperCase(); 

    try { 
     if (sMethod == "GET") 
     { 
     xmlhttp.open(sMethod, sURL+"?"+sVars, true); 
     sVars = ""; 
     } 
     else 
     { 
     xmlhttp.open(sMethod, sURL); 
     xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1"); 
     xmlhttp.setRequestHeader("Content-Type", 
      "application/x-www-form-urlencoded"); 
       xmlhttp.setRequestHeader("Content-length", sVars.length); 
     } 
     xmlhttp.onreadystatechange = function(){ 
     if (xmlhttp.readyState == 4 && !bComplete) 
     { 
      bComplete = true; 
      fnDone(xmlhttp); 
     }}; 
     xmlhttp.send(sVars); 
    } 
    catch(z) { return false; } 
    return true; 
    }; 
    return this; 
}, 
tOrigin: function(origin){ 
    this.origin = origin; 
}, 
tObject: function(origins,url,apik){ 
    this.origins=origins; //this is an array 
    this.url=url; 
    this.apik=apik; 
    this.host= "http://localhost:3000/";//window.location.hostname; 
} 
    runMe: function(){ 
        var t = new tObject(['this','word','word me please','and me please','word','word','okay','word','go','go'],window.location.href,"helloapik"); 
    // console.log(t); 

     ajax = new Ajax(); 
     ajax.connect("http://localhost:3000/","POST",JSON.stringify(t), callBackFunc) 
    } 

这就是我得到我的轨道服务器日志:

Parameters:

{"{\"origins\":"=>{"{\"origin\":\"this\"},{\"origin\":\"word\"},{\"origin\":\"word me please\"},{\"origin\":\"and me please\"},{\"origin\":\"word\"},{\"origin\":\"word\"},{\"origin\":\"word\"},{\"origin\":\"okay\"},{\"origin\":\"word\"},{\"origin\":\"go\"},{\"origin\":\"go\"}"=>{",\"url\":\"file:///Users/waheed/Desktop/untitled.html\",\"apik\":\"helloapik\",\"host\":\"http://localhost:3000/\"}"=>nil}}}

+3

标题是为您的问题的3 - 5字摘要,而不是问题本身。 – Yacoby 2010-04-05 19:32:28

+0

-1为标题,以及否认jQuery为此样板复制+粘贴代码。 – 2010-04-05 19:33:38

+0

其实我还没有看到这个标题这么长,我肯定会销毁这个问题,如果我可以,或者至少改变标题,再次抱歉,虽然我不否认jQuery的任何东西,谢谢 – Waheedi 2010-04-06 06:22:02

回答

1

如果整个jQuery库太你可以在很大的头顶上掏出它并挑选你需要的东西。

无论如何,我会说这是一个问题,你如何解析服务器端,似乎有一些后续的Ruby魔术正在进行,但不知道你的服务器端代码很难说出发生了什么事情。

+0

实际上你不需要知道服务器端,如果你知道轨道,你会知道为什么。 – Waheedi 2010-04-06 06:19:11

+0

但你可能需要修复问题服务器端。我不知道rails,但经过一番搜索后,我建议你看一下'raw_post()'必须提供什么,或者尝试request.env ['RAW_POST_DATA']的内容。我无法尝试,所以这只是Google告诉我的一个前沿。 – aaaaaaaaaaaa 2010-04-06 15:03:40

+0

我是一个坚决反对jQuery的人。虽然,我是一位反jQuery的拥护者,但我确实认为它很有用,可以在适用的地方借用。 +1对它进行切割 – vol7ron 2010-10-07 01:54:36

相关问题