window.location is not woking

I'm using jQuery with Django in server-side. What I'm trying to do is to get some text from the user through the form and simultaneously displaying the text in the canvas area like about.me and flavors.me does. Then the user drag the text in the canvas area to the desired position and when they click the next button,the data must be stored in the database and redirect to the homepage. Everything is working perfect(the datas are stored in the database) except when I click the button which I set window.location to "http://127.0.0.1:8000". But I'm not getting to that page when I click the button.

I'm getting some errors in Django server:

error: [Errno 32] Broken pipe ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 51161) Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock

Here is my html: https://gist.github.com/2359541

Django views.py:

from cover.models import CoverModel from django.http import HttpResponseRedirect

def coverview(request): if request.is_ajax(): t = request.POST.get('top') l = request.POST.get('left') n = request.POST.get('name') h = request.POST.get('headline') try: g = CoverModel.objects.get(user=request.user) except CoverModel.DoesNotExist: co = CoverModel(top=t, left=l, name=n, headline=h) co.user = request.user co.save() else: g.top = t g.left = l g.name = n g.headline = h g.save() return HttpResponseRedirect("/")

urls.py:

url(r'^cover/check/$', 'cover.views.coverview'), url(r'^cover/$', login_required(direct_to_template), {'template': 'cover.html'}),

Could anyone help me?

Thanks!

-------------Problems Reply------------

There's really not enough information in your question to properly diagnose this, but you can try this:

It's always a bad idea to hard-code a domain name in your JS. What happens when you take this to production, for example? If you want to send the user to the homepage (presumed from the location being set to http://127.0.0.1:8000/), then set the location simply to /. That will ensure that it will always go to the site root regardless of the IP address, domain name or port.

Part of the problem is that you're trying to post data, and then immediately leaving the page by using window.location. You should only change the window.location whenever you get the response back from the $.post().

$.post("check/", { top: t, left: l, name: n, headline: h}, function(data) {
window.location.href = "/";
});

Notice also that I removed the hardcoded URL. Use a relative one here, like Chris said.

If it still isn't working, you need to check for Javascript errors in the lines above. Use Firebug, Chrome Dev Tools, Opera Dragonfly, something. Check to make sure your POST is actually going through, and post more data about that back here.

Category:javascript Views:0 Time:2012-04-11

Related post

  • help: reloading a page via ajax - when window.location=self.location doesn't work 2008-10-08

    so here on my homepage i got a <ul id="login"> <li> <a id="loginswitch" href="./login-page">log-in</a> | </li> <li> <a id="signupswitch" href="./signup-page">sign-up</a> </li> </ul> so via m

  • windows.location.href not working on Firefox3 2008-11-08

    We have a JavaScript function named "move" which does just "windows.location.href = any given anchor". This function works on IE, Opera and Safari, but somehow is ignored in Firefox. Researching on Google doesn't produce a satisfactory answer why it

  • pulling location.href or window.location from fire fox without it being encoded 2008-11-11

    I'm passing a url through google translate and in my location bar on Fire fox, the url looks as it should: http://72.14.235.104/translate_c?hl=en&langpair=en|ru&sl=ru&tl=ru&u=http://something.something/something/.....orig_term%3Dмаляр

  • IS it safe to use window.location to query the GET params of a page? 2009-01-20

    I'm doing a peer review and I've found people using window.location.search to check what paremetes have been sent to a given (search) page. Is it safe to do so? I was thinking that we could probably print the parameters in the HTML output inside a sc

  • Can I update window.location.hash without having the web page scroll? 2009-03-14

    Using JavaScript, is there a way to update window.location.hash without scrolling the web page? I have clickable title elements that toggle the visibility of a div directly beneath them. I want the /foo#bar in the history when clicking titles but don

  • JQuery Modal Popup after window.location 2009-04-13

    Below is the information required for this problem. default.aspx /test/default.aspx When default.aspx loads the user clicks a button which should then redirect to /test/default.aspx. I have the modal popup working just not with the redirect and ideas

  • doing substring in window.location.hash 2009-05-05

    Somehow window.location.hash is being handled differently in different browsers. If I have a url as follows http://maps-demo.bytecraft.com.my/postdemo/parcel #parcel/history/1?as=json&desc[]=ctime&desc[]=history_id and I am interested in gett

  • Condition to test if a word exists in window.location.href 2009-05-22

    I want to test if a word ["sublanguageid-all" to be specific] is present in the current address of the page using an 'if' condition. I've tried /sublanguageid-all/g, but I'm not able to put it in an if-statement --------------Solutions------------- D

  • window.location.hash issue in IE7 2009-06-01

    We have a javascript function that should "move" a page to a certain position using anchors. This function just does window.location.href = "#" + hashName. This works in FF, but not in IE. I tested this code using IE7 under Windows XP. I have tried u

  • .NET MVC jQuery relative path for window.location 2009-06-15

    I have a real simple problem, but can't seem to figure it out. The following doesn't work because of the way MVC builds the URL (It includes all the route information). I want pathname to return the virtual directory path only. All I'm doing is redir

  • Lost chronology using window.location.href 2009-06-23

    I have a problem with a javascript set of functions that I made. This functions walk the entire Html page and then add the onclick event to every anchor it finds. It do some check on the anchor href and redirect to it (using window.location.href) My

  • window.location = #anchor doesn't work in IE 2009-07-23

    On this map: http://web.pacific.edu/documents/marketing/campus-map/version%202/stockton-campus-2.0.htm I have an anchor at the top, and I want the page to jump to the anchor when a link is clicked. I'm currently using window.location = '#top'; It wor

  • How to get a subdomain using window.location? 2009-07-29

    If I have a hostname such as: http://sample.example.com and in Javascript I do window.location.hostname, would I get "example.com" or "sample.example.com"? If not, how would I be able to get sample.example.com? --------------Solutions------------- Ye

  • Problem running my project in IE 6.0 and 7.0 (window.location)? 2009-08-04

    My project is running perfectly in Firefox, google chorme and IE 8.0 But it is not working on IE 6.0 or 7.0 I realized that it is given problem at window.location I am placing my code over here to show what i am doing. function GetEmailId() { var url

  • Potential problems setting window.location.hash 2009-08-11

    I have some javascript code which, at one point, sets window.location.hash to a specific string. This works fine in Firefox 3, but I want to know if I will run into problems with this later, i.e. is this a cross-browser solution (IE6 included)? Also,

  • ExternalInterface.call("window.location.host.toString") 2009-08-12

    I wrote a flex application that get the host string from the browser using this code ExternalInterface.call("window.location.host.toString") This line of code work prefectally to get the host string in both Firefox and Opera. However, when using IE,

  • Sending $_SESSION variables with window.location redirect 2009-08-15

    My problem: I have few buttons in the page I'm modifying - they have onclick events: javascript:window.location.href='http://www.another.page.com/'; return false; I have to send $_SESSION variable to redirected page. I can't do it in previous page be

  • Setting window.location.hash to null in Safari 3+ causes it to be set to # 2009-08-31

    Setting window.location.hash to null in Safari 3+ causes it to be set to #, e.g. window.location.hash = '#foo' => #foo But, window.location.hash = null => # Same occurs if you set it to an empty string instead of null. Behavior definitely occur

  • How to remove the hash from window.location with JavaScript without page refresh? 2009-09-09

    So, if I have http://example.com#something, how do I remove #something, without causing the page to refresh? I attempted the following solution: window.location.hash = ''; However, this doesn't remove the hash symbol # from the URL. --------------Sol

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.188 (s). 11 q(s)