Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

$(document).ready (function()I $("#test Poll"). click (function(e) e preventDefault(); post("process.php", $("#test Po .serialize (),function (data) $("#testPo ).html (data); return false; h); h);

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;
})
})