1

What I want is to get a proper parameter, if you see the parameter been logged can you tell me if the problem's in my JavaScript?

First run the runMe function

 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)
    }

This is what I'm getting in my rails server log:

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}}}

0

1 Answer 1

1

If the whole jQuery library is too much overhead you could gut it and pick what you need.

In any case, I'd say this is a problem with how you parse serverside, there seems to be some trailing s Ruby magic going on, but without knowing your serverside code it is quite hard to tell what is going on.

Sign up to request clarification or add additional context in comments.

3 Comments

actually you dont need to know the server side, if you know rails you would know why.
But you would probably need to fix the problem server side. I don't know rails, but after a bit of googling I'd suggest you look at what raw_post() has to offer, or try the content of request.env['RAW_POST_DATA']. I can't try it out, so this is just a forward of what Google tells me.
I'm someone that stands firm against jQuery. While, I'm an anti-jQuery advocate, I do say that it is useful and can be borrowed-from, where it applies. +1 for gutting it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.