Jump to content
xisto Community
Sign in to follow this  
szupie

Using The Post Method Without HTML Yeah, See the Above Line.

Recommended Posts

I'm making a Firefox extension, and I need to use the POST method, which apparently is almost exclusively for HTML. Writing Firefox extensions is just like creating a web page, but the only difference is that you should avoid using HTML at all. Javascript, XML, etc. are fine. I've tried using the XMLHttpRequest function with AJAX, but I couldn't get it to work. So does anyone know how to POST information using any language but HTML? (Not GET. But it'd be much easier if I could use GET.)

Share this post


Link to post
Share on other sites

Yeah, POST and GET are exclusive to HTML. All other program languages have functions written to be able to use POST and GET.I think you'll need to use sockets to pass data between the extention and the script. Unfortunately I have no idea of how to help you.You might try some learn by example and take a peak at a similar extention if that is possible. I'm not a FF user and not interested in writting extentions for it. Just thought I should try to stear you away from the POST method.Let me know if I'm wrong, I'd love to learn a new method. :)vujsa

Share this post


Link to post
Share on other sites

Completely wrong, POST is a method of the HTTP Protocol, which means HTML is not the only language that can do it, but it may seem like the easiest way. So any HTTP capable client should be able to submit POST methods.Maybe the RFC2616 will help you understand what the requirements are, unless you do want some code shown, any particular language? Remember you must follow the rules of message transmission for it to work as intended.Cheers,MC

Share this post


Link to post
Share on other sites

My question is why couldn't you get AJAX to work ? It's so darned simple. Need any help on that, check out the Shoutbox files - or the content of the Credits Reporter extension I was designing. Nothing better than AJAX to go with FF Extensions.

Share this post


Link to post
Share on other sites

-----Below was written on 1/25/2005, 07:40 AM EST-----szupie

 

mastercomputers: I googled the RFC2616 thing. Wow... So much to read... I just wanted to know what languages would make the job the easiest.

 

miCRoSCoPiC^eaRthLinG: When I try AJAX in my extension, my script would stop in the middle, but it doesn't give any error report. I'm thinking it's something wrong with the send() part of the code. When I try the AJAX code in HTML, I get this error: Error: uncaught exception:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.setRequestHeader]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: file:///D:/xxxNameRemovedxxx/extensions/astau/chrome/chromeFiles/content/test.htm :: <TOP_LEVEL> :: line 6"  data: no]

I don't know what that means, since Mozilla doesn't have a manual on what error codes mean (or do they?). I'll try looking through your credits extension and the shoutbox code to see what I'm doing wrong.

 

-----Posts Merged-----szupie

-----Below was written on 1/26/2005, 09:19 PM EST-----szupie

 

OK, I found out that I had 2 problems in my javascript. The first one was with the send() statement. I did not put quotes around the parameters I wanted to pass (no one told me it needed to have quotes!). The second problem was in a later part of the script, where I tried to write the response to a new page. I was wrong about the AJAX not working, because this part was just plain javascript.

 

So now, my problem is this: how can I send information to a page with AJAX? I've used this page as a test page for my extension. For the send statement, my code is http_request.send('md5=hello');. Then, when the response comes back, I create a new page and document.write the response to the page. This page's status bar never finishes loading, and the page doesn't seem to have taken any parameters. I've studied the shoutbox code (the credits extension didn't have POST in its code), but I don't see how I've made a mistake. Did anyone spot anything wrong with my code?

Share this post


Link to post
Share on other sites

I did not put quotes around the parameters I wanted to pass (no one told me it needed to have quotes!).

 

Well before doing that just read the docs atleast once.. i hate reading docs but atleast i go through once what are the parameters possible and what it is types....

 

For that send statement, my code is http_request.send('md5=hello');. Then, when the response comes back, I create a new page and document.write the response to the page. This page's status bar never finishes loading,

 

Try to use like this

xmlHttpobj.open("POST","yourpage.php?md5=hello");

xml.Httpobj.send("");

 

check out your server is working properly..

 

and the page doesn't seem to have taken any parameters. I've made a mistake. Did anyone spot anything wrong with my code?

 

due to the browser behavious also u get some error (so problem is not from ur side)

Sometimes if u make request to some scripts repeatedly the broswer checks its cache if it available it gives from cache .. it does not go to original server.. So u will get confuse becaz u will the ouput that makes u feel that AJAX is working but u get the same result everytime becaz is it static from cache... u wont get proper response ... well how to solve this...

There is a solution for every problem.....

var myRand = parseInt(Math.Random() * 999999);

xmlhttpobj.open("POST",yourpage.php?md5=Hello&myRand="+myRand);

xmlhttpobj.onreadtstatechange = func.......

xmlhttpobj.send("");

so ur url is not the same at any time becaz a new random is attached so that it does not get one from cache... it feels it is something new and ask the server........

 

hope u can solve it if u get still problem post the AJAX related problem...

 

may i know what extension u r writting.......

 

:D

Share this post


Link to post
Share on other sites

Can't you use POST in XML?I found something like this on w3schools and when I just went to have a look I got a domain parked message.Anyway, I would love to give you a link but I'm sure Google, the god of link givers, would be nice enough to help you out.

Share this post


Link to post
Share on other sites

I'm making a Firefox extension, and I need to use the POST method, which apparently is almost exclusively for HTML. Writing Firefox extensions is just like creating a web page, but the only difference is that you should avoid using HTML at all. Javascript, XML, etc. are fine. I've tried using the XMLHttpRequest function with AJAX, but I couldn't get it to work. So does anyone know how to POST information using any language but HTML? (Not GET. But it'd be much easier if I could use GET.)


Im not really sure i get what yu want to do... but this might help. I use AJAX to submit my form using the Post method. Heres my code:

function AJAXInteraction(url, callback) {	var req = init();	req.onreadystatechange = processRequest;			function init() {	  if (window.XMLHttpRequest) {		return new XMLHttpRequest();	  } else if (window.ActiveXObject) {		  return new ActiveXObject("Microsoft.XMLHTTP");	  }	}		function processRequest () {	  // readyState of 4 signifies request is complete	  if (req.readyState == 4) {		// status of 200 signifies sucessful HTTP call		if (req.status == 200) {		  if (callback) callback(req.responseXML);		}	  }	}	this.doGet = function() {	  req.open("GET", url, true);	  req.send(null);	}		this.doPost = function(str) {	  req.open("POST",url,true);	  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");	  req.send(str);	}}

And I use it like this:
var url = "/MyServlet";var querystr = "opt=NBCA&optionx=APPROVE&date_created=${param.date_created}";var ajax = new AJAXInteraction(url, approveResponse);			ajax.doPost(querystr);


You should be able to adapt this to suit your needs :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.