JS object explanation needed

S

sammy

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
 
J

JR

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top