JS object explanation needed

Discussion in 'Javascript' started by sammy, Jul 7, 2009.

  1. sammy

    sammy Guest

    I have finaly had reason to look at JS, but I can't find any detailed
    info on the web about objects.
    I trying to create a requiest for GM_xmlhttpRequest()


    // obj1 = { method:"POST", url:"192.168.0.6:7777",
    // headers:{
    // "User-Agent":"monkeyagent",
    // "Accept":"text/monkey,text/xml"},
    // onload:function(details) {
    // alert([
    // details.status,
    // details.statusText,
    // details.readyState,
    // details.responseHeaders,
    // details.responseText].join("\n")) }
    // };

    The above is almost verbatim from mozilla docs ( which I can't now find )

    obj1 = { method:"POST", url:"http://voidstar:7777",
    headers:{
    "User-Agent":"monkeyagent",
    "Accept":"text/monkey,text/xml",

    "Content-type":"application/x-www-form-urlencoded" },
    data: "data here?" };

    // obj1 = { method:"POST", url:"http://voidstar:7777",
    // headers:{
    // "User-Agent":"monkeyagent",
    // "Accept":"text/monkey,text/xml" }
    // };
    // obj1.data = response
    GM_xmlhttpRequest( obj1 )


    I guess I am not sure what is realy happening in the original example.
    Is it creating object with method , headers and "?? nameless function"
    members?
    I have tried:
    obj1.data = posted_data_string
    to add member var data but no joy, so how can I add my data string to this?

    Many thanks
     
    sammy, Jul 7, 2009
    #1
    1. Advertising

  2. sammy

    JR Guest

    On Jul 6, 8:46 pm, sammy <> wrote:
    > I have finaly had reason to look at JS, but I can't find any detailed
    > info on the web about objects.
    > I trying to create a requiest for GM_xmlhttpRequest()
    >
    > //        obj1 = {  method:"POST",  url:"192.168.0.6:7777",
    > //                              headers:{
    > //                              "User-Agent":"monkeyagent",
    > //                              "Accept":"text/monkey,text/xml"},
    > //                              onload:function(details) {
    > //                              alert([
    > //                              details.status,
    > //                              details.statusText,
    > //                              details.readyState,
    > //                              details.responseHeaders,
    > //                              details.responseText].join("\n")) }
    > //                              };
    >
    > The above is almost verbatim from mozilla docs ( which I can't now find )
    >
    >          obj1 = {  method:"POST",  url:"http://voidstar:7777",
    >                                headers:{
    >                                "User-Agent":"monkeyagent",
    >                                "Accept":"text/monkey,text/xml",
    >
    > "Content-type":"application/x-www-form-urlencoded"  },
    >                                data: "data here?"  };
    >
    > //        obj1 = {  method:"POST",  url:"http://voidstar:7777",
    > //                              headers:{
    > //                              "User-Agent":"monkeyagent",
    > //                              "Accept":"text/monkey,text/xml"  }
    > //                                };
    > //        obj1.data = response
    > GM_xmlhttpRequest( obj1 )
    >
    > I guess I am not sure what is realy happening in the original example.
    > Is it creating object with method , headers and "?? nameless function"
    > members?
    > I have tried:
    > obj1.data = posted_data_string
    > to add member var data but no joy, so how can I add my data string to this?
    >
    > Many thanks


    There is an example at the GreaseMonkey site:

    http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html

    The following code fetches the Atom feed from http://greaseblog.blogspot.com/
    and displays an alert with the results.

    GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://greaseblog.blogspot.com/atom.xml',
    headers: {
    'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
    'Accept': 'application/atom+xml,application/xml,text/xml',
    },
    onload: function(responseDetails) {
    alert('Request for Atom feed returned ' +
    responseDetails.status +
    ' ' + responseDetails.statusText + '\n\n' +
    'Feed data:\n' + responseDetails.responseText);
    }
    });

    --
    JR
     
    JR, Jul 7, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VK
    Replies:
    1
    Views:
    441
    Richard Tobin
    May 18, 2006
  2. Replies:
    9
    Views:
    390
    Christian Bau
    Feb 16, 2006
  3. NoNeYa
    Replies:
    42
    Views:
    1,241
    John W. Kennedy
    Aug 22, 2007
  4. korean_dave
    Replies:
    0
    Views:
    385
    korean_dave
    May 19, 2008
  5. korean_dave

    Dummy explanation to win32com needed

    korean_dave, Oct 22, 2008, in forum: Python
    Replies:
    2
    Views:
    331
    Tim Golden
    Oct 23, 2008
Loading...

Share This Page