2 Replies - 2740 Views - Last Post: 01 March 2013 - 04:19 PM

#1 ziggy786   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 26-February 13

How to refresh a div using JQuery?

Posted 01 March 2013 - 01:12 PM

I've got a navigation bar that is static on the top of the page. On the bar there is a link to "login or register". If you click login it opens a lightbox login form. I want it that when the user clicks the submit button the div container "login or register" refreshes to show "You are logged in". Currently when the user logs in, he/she has to refresh the page to change the text. I want it so that you can click submit and it refreshes only the div without refreshing the page using JQuery. This is the code that i have that doesn't work:
$('#submit').on('click', function(){

$("#login_or_register").load(".#login_or_register");
$("#login").hide().html(data).fadeIn('fast');
return false;

}); 

This post has been edited by Atli: 01 March 2013 - 04:12 PM
Reason for edit:: Fixed the [code] tags.


Is This A Good Question/Topic? 0
  • +

Replies To: How to refresh a div using JQuery?

#2 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,527
  • Joined: 12-December 12

Re: How to refresh a div using JQuery?

Posted 01 March 2013 - 01:24 PM

(".#login_or_register");

remove the dot as that refers to a class-name rather than an id - the syntax is incorrect.

This post has been edited by andrewsw: 01 March 2013 - 01:25 PM

Was This Post Helpful? 0
  • +
  • -

#3 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: How to refresh a div using JQuery?

Posted 01 March 2013 - 04:19 PM

Hey.

You should look up the jQuery.load docs and go over how it's actually supposed to be used. In short, the first function parameter should always be the URL of the page you want loaded into the jQuery element you are calling the function on.

However, that doesn't seem to be what you should be using there. It looks like you are trying to submit the form via AJAX, and then change the contents of the box. In that case, .load is probably not the function you want to be using. Instead, look up the uses of jQuery.post(), jquery.get(), or just the basic jQuery.ajax() functions. All have different uses that can be useful in this situation. More likely than not, though, you'll want to be using $.post(). That's the one you use to send POST data to the server for processing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1