How To Display Non-Modal Popup From Resulting Asynchronous Javascript Request

330 views
Skip to first unread message

curious1

unread,
Jul 23, 2012, 4:42:25 PM7/23/12
to django...@googlegroups.com

I have a django application already developed which I'm trying to use to experiment with asynchronous javascript without using any of the standard JQuery type libraries, in order to better learn and understand AJAX concepts. The application itself has been written using python 2.7.1 and django 1.2.4. My view just returns the "request.responseText" from the asynchronous javascript call returns text only from a django view (via "return HttpResponse(message)"). I would try to use the "render_to_response()" shortcut function, but then it doesn't seem like the javascript callback function would be needed or used, so I hesitate to do so. I would like to display the returned text data on a new non-modal popup screen (using window.open()) so that the user can view it, while still interacting with the main screen, from which the asynchronous javascript call was originally issued. However when I initiate the asynchronous call and the popup is displayed I'm getting a 404, because apparently the url that I'm supplying for the popup is in error in some way. The 404 verbage returned in the popup looks like this:


Page not found (404)

Request Method:

GET

Request URL:

http://127.0.0.1:8000/mediahelp/mediaHelpPopup.html

 Using the URLconf defined in streamingmedia.urls, Django tried these URL patterns, in this order:
1.^mymedia/
2.^mediaadmin/
3.^mediahelp/ ^$
4.^mediahelp/ ^comphelp/$
5.^admin/

The current URL, mediahelp/mediaHelpPopup.html, didn't match any of these.
 
 
So far I've tried numerous variations for the popup's url with only 404's resulting. Do I need to return something other HttpResponse in my asynchronous view in order to get this to work? At this point since I'm rather new to attempting AJAX I'm just looking for the simplest solution for displaying the returned data in a non-modal popup. Can someone help or point me to a good and simple (using simple javascript only) tutorial for doing something like this?
 
 
 
 
 

Tomas Neme

unread,
Jul 23, 2012, 8:34:55 PM7/23/12
to django...@googlegroups.com
your error's got nothing to do with AJAX. As the very helpful error
message you're getting, there's no URL that matches your requested
path:

> Request URL:
>
> http://127.0.0.1:8000/mediahelp/mediaHelpPopup.html
>
> Using the URLconf defined in streamingmedia.urls, Django tried these URL
> patterns, in this order:
> 1.^mymedia/
> 2.^mediaadmin/
> 3.^mediahelp/ ^$
> 4.^mediahelp/ ^comphelp/$
> 5.^admin/

I don't know where did you get the 'mediaHelpPopup.html' part of your
URL, but it's quite clear it doesn't match any of those urls you've
got set up.

So if you give us some more details on your idea for this popup, where
does the data come from, and why do you feel the need to make a call
to some phantom html file
(https://docs.djangoproject.com/en/1.4/topics/http/urls/, and
especially http://www.w3.org/Provider/Style/URI).

Basically, you need to have a view that renders your popup's HTML, and
that view needs to be linked to an URL.

--
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

curious1

unread,
Jul 24, 2012, 10:03:49 AM7/24/12
to django...@googlegroups.com
OK. sorry for not providing more information previously. Currently here's the 404 I'm getting back when I submit the asynchronous request:

Page not found (404)

Request Method:
GET

Request URL:

 Using the URLconf defined in streamingmedia.urls, Django tried these URL patterns, in this order:
1.^mymedia/
2.^mediaadmin/
3.^mediahelp/ ^$
4.^mediahelp/ ^comphelp/$
5.^admin/
The current URL, mediahelp/comphelp/mediaHelpPopup.html, didn't match any of these.
 
The code from the comphelp url view is very basic and looks like this:
def component_help(request):
    view = "component_help"
    dctnry = {}
    reqGET = request.GET.copy()
    if reqGET.has_key('fieldId'):
        field_value = reqGET['fieldId']
    else:
        field_value = "NONE FOUND"
    message = "This is a test message!...FIELD-ID="+field_value
    dctnry['helpdata'] = message
    return HttpResponse(message)
 
Currently I only have it set up to return a message just to prove that the call was made and returned  successfully. This is all very basic code at this point since I'm just trying to set up all of the needed functionality.
Here's the html page in question:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MEDIA-HELP POPUP SCREEN</title>
</head>
<body>
</body>
</html>
 
Finally here are the javascript routines which are supposed to display the data returned in the popup:
 
function popup(responseData)
  {
     var href = "../../mediahelp/comphelp/mediaHelpPopup.html"; 
     var windowname = "Super Admin Reports POPUP";  
      if(!window.focus)
      {
          return true;
      }
      helpdatascreen = window.open(href, windowname,'width=400,height=200,scrollbars=yes');
      helpdatascreen.body.appendChild = responseData;
      helpdatascreen.focus();
      return false;
  }
function displayHelpData()
  {     
      if(request.readyState == 4)
      {
          if(request.status == 200)
         
          {
              popup(request.responseText);
          }
      }
  }
 
So is there a problem with the url used above(the href field in the popup function)? If so what's wrong with it? Previously the call seemed to be successfull as well as the return, since I was previously able to display the returned message in an alert. So I wanted to actually display the returned data in a popup window, which is my ultimate goal and that is where things stand so far in my progress, up to the point to where I started getting the current 404 situation that you now see above. Thanks for the help.
 

Daniel Roseman

unread,
Jul 24, 2012, 10:26:58 AM7/24/12
to django...@googlegroups.com
On Tuesday, 24 July 2012 15:03:49 UTC+1, curious1 wrote:
 
So is there a problem with the url used above(the href field in the popup function)? If so what's wrong with it? Previously the call seemed to be successfull as well as the return, since I was previously able to display the returned message in an alert. So I wanted to actually display the returned data in a popup window, which is my ultimate goal and that is where things stand so far in my progress, up to the point to where I started getting the current 404 situation that you now see above. Thanks for the help.

<snip>

What part of Tomas's reply didn't you understand? Yes, there is a problem with that URL, because it doesn't match any of the URLs in your urlconf. There is no URL matching anything ending in 'html'. Perhaps you meant just /mediahelp/comphelp/  ?
--
DR.

Tomas Neme

unread,
Jul 24, 2012, 11:05:29 AM7/24/12
to django...@googlegroups.com
> The current URL, mediahelp/comphelp/mediaHelpPopup.html, didn't match any of
> these.
>
> The code from the comphelp url view is very basic and looks like this:
> def component_help(request):
> view = "component_help"
> dctnry = {}
> reqGET = request.GET.copy()
> if reqGET.has_key('fieldId'):
> field_value = reqGET['fieldId']
> else:
> field_value = "NONE FOUND"
> message = "This is a test message!...FIELD-ID="+field_value
> dctnry['helpdata'] = message
> return HttpResponse(message)

then why are you calling /mediahelp/comphelp/mediaHelpPopup.html?

what exactly do you think that html filename in the end does to your call?

And.. no, I could make a lot of questions trying to lead you slowly to
the answer, but what I really think is that you need to do the
tutorial again, and understand urlconfs, views and templates.
https://docs.djangoproject.com/en/dev/intro/tutorial01/

I'll give you the short of it because I'm not your teacher: what you
actually want to do is call '/mediahelp/comphelp/' and from the view
you'll want to `return render_to_response('mediaHelpPopup.html',
dctnry)`

curious1

unread,
Jul 24, 2012, 12:31:31 PM7/24/12
to django...@googlegroups.com
Thanks for the help. You revealed some things to me which I hadn't understood or tried before, but now I have. The 404 problem has been resolved and things are working much better. Thanks again.
Reply all
Reply to author
Forward
0 new messages