Rectangle 27 1

Perhaps the problem is the behavior of input type image. https://developer.mozilla.org/es/docs/Web/HTML/Element/Input Try to use e.preventDefault() in your function and no Submit should be done.

$( "#test" ).click(function( event ) {
  event.preventDefault();
var formValue = $('#TP').serialize();
$.post('saveIndvQuestionnaire.jsp?'+formValue+'&category='+category,
        function(data) {
    return false;
});

});

You can use another html control to achieve this like a href with a Image:

<a href="#" onClick="alert('Hello World!')"><img title="The Link" /></a>

I used href instead of input type image and now my code is working fine.. Thaks

How to stop jquery ajax page reload on success or failure - Stack Over...

jquery ajax
Rectangle 27 1

I think you can also Like this

$('YourForm').submit(function(e){
   e.preventDefault();
   formdata=$(this).serialize();
   $.ajax({
      type: "POST",
      url: url,
      data: formdata
      }).done(function(data){
  //do something
   });
});

How to stop jquery ajax page reload on success or failure - Stack Over...

jquery ajax
Rectangle 27 1

<input id="test" type="image" onclick="return javascript:AjaxCall('Test');" src="../images/v10/larrow.png">

You should get "return" the response onclick.

How to stop jquery ajax page reload on success or failure - Stack Over...

jquery ajax
Rectangle 27 16

Modify the function like this:

function sendForm(e){
  e.preventDefault();
}

And as comment mentions, pass the event:

onclick = sendForm(event);
$('#form-button-submit').on('click', function(e){
   e.preventDefault();

   var name = $('input#name').val(),
       email = $('input#email').val(),
       comments = $('textarea#comments').val(),
       formData = 'name=' + name + '&email=' + email + '&comments=' + comments;

    $.ajax({
      type: 'post',
      url: 'js/sendEmail.php',
      data: formData,
      success: function(results) {
        $('ul#response').html(results);
      }
    });
});

Don't forget that the event object needs to be passed into the function call

onclick="sendForm(this)"
event

Thank you but it doesn't work. Thing is just before it refreshes I can see that ul was populated. I tried aside from preventDefault() using return false in the onClick such as "sendForm(); return false;" putting return default after ajax, having both preventDefault() and return false; and any combination of placements really.

@VettanMaximillion Get rid of the inline event handler, and then see my "update 2"

javascript - Prevent page reload and redirect on form submit ajax/jque...

javascript php jquery html ajax
Rectangle 27 7

It is not possible to stop the user from page reload/page close if the user wants it. Two methods which you can use are as follows:

You can ask for a confirmation like this:

<script>
window.onbeforeunload = function (e) {
e = e || window.event;

// For IE and Firefox prior to version 4
if (e) {
    e.returnValue = 'Sure?';
}

// For Safari
return 'Sure?';
};
</script>

You can preventDefault on pressing of F5 key using:

document.onkeydown = function(event) {
  if(window.event){
        event.preventDefault();
  }
}

i try your answer, but as i said, my problem is to avoid calling windows.onload

@mbayloon Thats impossible, as mentioned in both the above answers.

Prevent User to reload page using jquery or javascript - Stack Overflo...

javascript jquery html refresh reload
Rectangle 27 4

<script type="text/javascript">
        $(document).ready(function(){

            // Check if the current URL contains '#'
            if(document.URL.indexOf("#")==-1)
            {
                // Set the URL to whatever it was plus "#".
                url = document.URL+"#";
                location = "#";

                //Reload the page
                 location.reload(true);
            }
        });
    </script>
<script type="text/javascript">
        $(document).ready(function(){

            // Check if the current URL contains '#'
            if(document.URL.indexOf("#")==-1)
            {
                // Set the URL to whatever it was plus "#".
                url = document.URL+"#";
                location = "#";

                //Reload the page
                 location.reload(true);
            }
        });
    </script>

Due to the if condition, the page will reload only once.

Due to the if condition, the page will reload only once.

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 4

<script type="text/javascript">
        $(document).ready(function(){

            // Check if the current URL contains '#'
            if(document.URL.indexOf("#")==-1)
            {
                // Set the URL to whatever it was plus "#".
                url = document.URL+"#";
                location = "#";

                //Reload the page
                 location.reload(true);
            }
        });
    </script>

Due to the if condition, the page will reload only once.

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 3

I believe that is not possible. Maybe change your approach. Reload only specific areas you want to refresh. In fact, these areas may be included in a single (and possibly big) div tag. Then you can just update that div using jQuery ajax. For that, load is the way to go:

$('#result').load('ajax/test.html', function() {
  alert('Load was performed.');
});

Here is a more specific example using links (just wrote it off of my head):

<script type="text/javascript">
   $(function(){
      $("#myLink").click(function(event){
        $("#updateThisDiv").load($this.attr('href'), function(){
          alert('div updated!');
        });             
        return false; // or event.preventDefault();
      });
    });
</script>

And your link would look like this:

<a href='pathTo/Page' id='myLink'>Link text</a>

...

<div id="updateThisDiv"></div>

if I did that will the URL change? because thats the thing I want to happen.

@user962206 The url will not change, although you could change the hash (see link below), just curious, why do you need to change the URL?: stackoverflow.com/questions/6478485/

Let's say I am in the index page. www.myapp.com, then let's say I click on a link called "events", I want that page to be loaded ajaxified. so in my link something like this will appear. www.myapp.com/events also, I would like to also add URL parameters. www.myapp.com/events?eventId=1 or something like that. and also to allow bookmarking

is there a way I can add a hash on the page?

What for? Did you get a chance to review the question to which I put a link in my previous comment?

javascript - Jquery Ajax loading the whole page except a certain div -...

javascript jquery ajax html
Rectangle 27 3

I believe that is not possible. Maybe change your approach. Reload only specific areas you want to refresh. In fact, these areas may be included in a single (and possibly big) div tag. Then you can just update that div using jQuery ajax. For that, load is the way to go:

$('#result').load('ajax/test.html', function() {
  alert('Load was performed.');
});

Here is a more specific example using links (just wrote it off of my head):

<script type="text/javascript">
   $(function(){
      $("#myLink").click(function(event){
        $("#updateThisDiv").load($this.attr('href'), function(){
          alert('div updated!');
        });             
        return false; // or event.preventDefault();
      });
    });
</script>

And your link would look like this:

<a href='pathTo/Page' id='myLink'>Link text</a>

...

<div id="updateThisDiv"></div>

if I did that will the URL change? because thats the thing I want to happen.

@user962206 The url will not change, although you could change the hash (see link below), just curious, why do you need to change the URL?: stackoverflow.com/questions/6478485/

Let's say I am in the index page. www.myapp.com, then let's say I click on a link called "events", I want that page to be loaded ajaxified. so in my link something like this will appear. www.myapp.com/events also, I would like to also add URL parameters. www.myapp.com/events?eventId=1 or something like that. and also to allow bookmarking

is there a way I can add a hash on the page?

What for? Did you get a chance to review the question to which I put a link in my previous comment?

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

javascript - Jquery Ajax loading the whole page except a certain div -...

javascript jquery ajax html
Rectangle 27 5

not possible at all to change the url or even query string of the browser without reloading only part you can change without refresh is #hash part of the url till html4

But in html 5 some kind of url change can be done by the new HISTORY API give it a try

php - Change browser address bar URL with jQuery & ajax without reload...

php jquery ajax
Rectangle 27 5

not possible at all to change the url or even query string of the browser without reloading only part you can change without refresh is #hash part of the url till html4

But in html 5 some kind of url change can be done by the new HISTORY API give it a try

php - Change browser address bar URL with jQuery & ajax without reload...

php jquery ajax
Rectangle 27 5

not possible at all to change the url or even query string of the browser without reloading only part you can change without refresh is #hash part of the url till html4

But in html 5 some kind of url change can be done by the new HISTORY API give it a try

php - Change browser address bar URL with jQuery & ajax without reload...

php jquery ajax
Rectangle 27 77

if(window.top==window) {
    // You're not in a frame, so you reload the site.
    window.setTimeout('location.reload()', 3000); //Reloads after three seconds
}
else {
    //You're inside a frame, so you stop reloading.
}
if(window.top==window) {
    // You're not in a frame, so you reload the site.
    window.setTimeout('location.reload()', 3000); //Reloads after three seconds
}
else {
    //You're inside a frame, so you stop reloading.
}
$('#div-id').triggerevent(function(){
    $('#div-id').html(newContent);
});
$('#div-id').triggerevent(function(){
    $('#div-id').html(newContent);
});
function updateDiv(){
    //Get new content through Ajax
    ...
    $('#div-id').html(newContent);
}

setInterval(updateDiv, 5000); // That's five seconds
function updateDiv(){
    //Get new content through Ajax
    ...
    $('#div-id').html(newContent);
}

setInterval(updateDiv, 5000); // That's five seconds

So, every five seconds the div #div-id content will refresh. Better than refreshing the whole page.

So, every five seconds the div #div-id content will refresh. Better than refreshing the whole page.

Thanks but I want the page to refresh/reload only ONCE (per browser session if possible)...?

Thanks but I want the page to refresh/reload only ONCE (per browser session if possible)...?

What's the trigger for reloading? a certain event or just time?

What's the trigger for reloading? a certain event or just time?

trigger: the first "call" of the page (sorry, my english is kinda poor g)

trigger: the first "call" of the page (sorry, my english is kinda poor g)

Try the solution i just edited

Try the solution i just edited

omfgroflmao, you're a genius! The "edited" version is exactly what I was looking for (the whole day btw...). Is it possible to add an optional time trigger here? So that location.reload is executed - let's say - after 3 seconds...? TIA (YOU've really made my day!)

omfgroflmao, you're a genius! The "edited" version is exactly what I was looking for (the whole day btw...). Is it possible to add an optional time trigger here? So that location.reload is executed - let's say - after 3 seconds...? TIA (YOU've really made my day!)

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 76

if(window.top==window) {
    // You're not in a frame, so you reload the site.
    window.setTimeout('location.reload()', 3000); //Reloads after three seconds
}
else {
    //You're inside a frame, so you stop reloading.
}
$('#div-id').triggerevent(function(){
    $('#div-id').html(newContent);
});
function updateDiv(){
    //Get new content through Ajax
    ...
    $('#div-id').html(newContent);
}

setInterval(updateDiv, 5000); // That's five seconds

So, every five seconds the div #div-id content will refresh. Better than refreshing the whole page.

Thanks but I want the page to refresh/reload only ONCE (per browser session if possible)...?

What's the trigger for reloading? a certain event or just time?

trigger: the first "call" of the page (sorry, my english is kinda poor g)

Try the solution i just edited

omfgroflmao, you're a genius! The "edited" version is exactly what I was looking for (the whole day btw...). Is it possible to add an optional time trigger here? So that location.reload is executed - let's say - after 3 seconds...? TIA (YOU've really made my day!)

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 2

<html>
    <head>
        <title>Reload (Refresh) Page Using Jquery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#reload').click(function() {
                    window.location.reload();
                });
            });
        </script>
    </head>
    <body>
        <button id="reload" >Reload (Refresh) Page Using</button>
    </body>
</html>
<html>
    <head>
        <title>Reload (Refresh) Page Using Jquery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#reload').click(function() {
                    window.location.reload();
                });
            });
        </script>
    </head>
    <body>
        <button id="reload" >Reload (Refresh) Page Using</button>
    </body>
</html>

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 2

<html>
    <head>
        <title>Reload (Refresh) Page Using Jquery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#reload').click(function() {
                    window.location.reload();
                });
            });
        </script>
    </head>
    <body>
        <button id="reload" >Reload (Refresh) Page Using</button>
    </body>
</html>

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 66

To reload, you can try this:

window.location.reload(true);

can you explain the bool argument?

The argument to the location.reload function determines if the browser should retrieve the document from the web-server. If needed to pull the document from the web-server again (such as where the document contents change dynamically) pass the argument as 'true' grizzlyweb.com/webmaster/javascripts/refresh.asp

this does not work in chrome and safari for some reason.

it works for me in chrome

'17 and still works on latest ver of firefox

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 66

To reload, you can try this:

To reload, you can try this:

window.location.reload(true);
window.location.reload(true);

can you explain the bool argument?

can you explain the bool argument?

The argument to the location.reload function determines if the browser should retrieve the document from the web-server. If needed to pull the document from the web-server again (such as where the document contents change dynamically) pass the argument as 'true' grizzlyweb.com/webmaster/javascripts/refresh.asp

The argument to the location.reload function determines if the browser should retrieve the document from the web-server. If needed to pull the document from the web-server again (such as where the document contents change dynamically) pass the argument as 'true' grizzlyweb.com/webmaster/javascripts/refresh.asp

this does not work in chrome and safari for some reason.

this does not work in chrome and safari for some reason.

it works for me in chrome

it works for me in chrome

'17 and still works on latest ver of firefox

Refresh (reload) a page once using jQuery? - Stack Overflow

jquery refresh reload
Rectangle 27 6

No, you can't. If a user wants to reload a page you cannot stop them.

Prevent User to reload page using jquery or javascript - Stack Overflo...

javascript jquery html refresh reload
Rectangle 27 5

What you want is to load the data again but not reload the div.

You need to make an Ajax query to get data from the server and fill the DIV.

javascript - Refresh/reload the content in Div using jquery/ajax - Sta...

javascript jquery html css ajax