The following segment of jQuery code does not work as expected. It seems clickin
ID: 3583009 • Letter: T
Question
The following segment of jQuery code does not work as expected. It seems clicking submit the 1st time works as expected, but subsequent clicks do synchronous requests.
[a] Identify the problem in words, and then
[b] suggest a solution using code.
Note: The data returned from process.php is all the HTML for the testPoll form.
Explanation / Answer
$("#testPoll").html(data)
$("#testPoll") is a form id
data: is what you get data from database i mean process.php
html: what the data get from process.php the data will replace with preset data.
if you append the data the previous data and what data come from process.php both are display. i think this is the problem for subsequent clicks.
You have to using append i mean $('#testPoll').append(data);
or
taking another div id and put in html
like another div id is divID
$('#divID').html(data);
Your code is working in my computer.
If you change above two types other wise it not working.
please delete the history. because the previous code store in cookie.
OR
open cntl+shift+n open a tab of incognito mode in this mode there have no history store so i think it works properly.
$(document).ready(function () {
$('#testPoll').click(function (e) {
e.preventDefault();
$.post("process.php", $('#testPoll').serialize(), function (data) {
$('#divID').html(data);
})
return false;
})
})