function nextPhoto() { jQuery.ajax({url: "/guess_the_group/workphoto.php", dataType: "html", type: "GET", success: function(msg) { //alert(""); document.getElementById('photoband').innerHTML = msg; }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert('Ошибка'); } }); } $(document).ready(function () { $("#PhotoForm").submit(function () { var str = $(this).serialize(); $.ajax( { type: "POST", url: "/guess_the_group/guess_group.php", data: str, success: function (msg) { $("#note").ajaxComplete(function (event, request, settings) { if (msg == 'OK') // Если сообщение отправлено, поблагодарим пользователя { result = '<div id="notification_ok">Угадал, наглый :)</div>'; } else { result = msg; } $(this).html(result); }); } }); return false; }); }); 

By the form I send the data to the php script, and get an answer if the answer is correct - one action, if not - another. When I click on the nextphoto button, the form on the Ajax stops working. Pkhp stupidly opens with a response. What can be wrong?

UPD: And here's another question, I made sure that if the answer is correct, the send button was removed.

 result = 'Угадал, наглый хорек :)'; $("#otp").hide('slow'); 

But now, when you click nextPhoto , the button is still removed. Although the answer has not yet been.

  • Try to open it in Mazille and look in the error console, maybe you have errors in your JavaScripts. - Farhod

2 answers 2

 function ajax_submit(){ var str = $("#PhotoForm").serialize(); $.ajax( { type: "POST", url: "/guess_the_group/guess_group.php", data: str, success: function (msg) { $("#note").ajaxComplete(function (event, request, settings) { if (msg == 'OK') // Если сообщение отправлено, поблагодарим пользователя { result = '<div id="notification_ok">Угадал, наглый :)</div>'; } else { result = msg; } $(this).html(result); }); } }); } 
  • Made a button like <input type = "button" onclick = "ajax_submit ()"> Begin the function $ ("# PhotoForm"). Submit (function () {var str = $ (this) .serialize (); $ .ajax ( {End of function}); return false;}); All right The button is not clickable became - Tchort
  • Corrected your answer. The button is correct. But the function should be as I wrote in the answer. You need to understand the meaning itself. Once you have removed the SUBMIT button, the form will not be sent, so you do not need to handle the sending event. We have created a button of the BUTTON type and handle the click event on it already - DemoS
  • Thanks, helped :) - Tchort
  • Updated the question. - Tchort
  • It is difficult to say something, edit your code in question as it is now, then we will try to figure it out - DemoS

Two solutions:

  1. return false; it is necessary to return not in the Ajax callback, but in the submit callback
  2. Do not submit the button of the form but the button and handle it with the click event.
  • 1. Has ceased to work at all. 2. Nothing has changed. - Tchort