I should have edited this before posting it. I'm not sure whether the
problem is with the Javascript or with the Python script.
Thanks.
On Aug 4, 1:47 pm, The Quill <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I'm trying to get AJAX POST to work properly using a local web.py
> server. It seems that I can create a successful POST using the first
> AJAX call. The second call fails, and then every subsequent call
> works! If I stop the server and restart, I get the same failure on the
> second call. I'm thinking this is a problem with my python code, but
> if not, could someone out there please correct me?
>
> Try it for yourself and you'll see what I mean. Also, you'll need to
> test this in Firefox and you might need to change the port to suit
> your configuration.
> Here's my HTML file:
> ******************************************************************
> <html>
> <head>
> <title>Firefox to Python and back...</title></head>
> <script>
> function alertContents() {
> if (http_request.readyState == 4) {
> if (http_request.status == 200) {
> var string = http_request.responseText;
> alert(string);
> } else {
> alert('There was a problem with the request.');
> }
> }
> POSTDATA = "";
> }
>
> var testvalue1 = '5';
> var testvalue2 = 'Hello World!';
> var POSTDATA = 'test1=' + escape(testvalue1) + '&test2=' +
> escape(testvalue2);
> function makeRequest(url, parameters) {
>
> try {
>
> netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
> } catch (e) {
> alert("Permission UniversalBrowserRead denied.");
> }
>
> http_request = false;
> http_request = new XMLHttpRequest();
> if (!http_request) {
> alert('Cannot create XMLHTTP instance');
> return false;
> }
> http_request.open('POST', url, true);
> http_request.setRequestHeader('content-type', 'text/plain');
> http_request.onreadystatechange = alertContents;
> http_request.send(POSTDATA);
> }
> </script>
> <body>
> <a href="#" onClick='makeRequest("http://127.0.0.1:8080/
> view","");'>makeRequest</a>
> </body>
> </html>
> ******************************************************************
>
> Here's my PYTHON file: app.py
> ******************************************************************
> import web, os, sys
>
> #load urls and matching classes
> urls = (
> '/view', 'view',
> '/test', 'test',
> '/quit','quit'
> )
> class view:
> def POST(self):
> print('Hello Test!')
> web.internalerror = web.debugerror
> if __name__ == "__main__":
> os.spawnv(os.P_NOWAIT,'runxulapp.bat',['',''])
> web.run(urls, globals())
> ******************************************************************
>
> TIA.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---