Hello! Please tell me what is wrong? If I send data using standard tools, registering the action attribute, then zayavka.php is executed; if I send via ajax, nothing happens. There is a form that must be checked before being sent to the server, after which, if everything is all right, send the data to another page - zayavka.php. Do I understand correctly that after sending ajax data, the zayavka.php page will start and execute all the code it contains? Is it necessary at the beginning to put a condition that if such and such data has come to us, then we do this and that?

$ (function () {

if (( document.anketa.vid_kredita.selectedIndex == 2) && ( document.anketa.obekt_nedvizhimosti[1].checked == true )) { $("#vid_kredita").css('border', 'red 1px solid'); error=3; } if ( ( document.anketa.region.selectedIndex == 1) && ( parseInt(razm_kredita) < 600000 ) ) { $("#razmer_kredita").css('border', 'red 1px solid'); error=4; } if(error==0){ var data = $('#firstname').val(); $.ajax({ type: "POST", url: "/stat/zayavka.php", data: "data="+data, success: function(html) { $("#result").empty(); $("#result").append(html); } }); } else{ if(error==3) err_text="Текст ошибки 3"; if(error==4) err_text="Текст ошибки 4"; $("#messenger").html(err_text); $("#messenger").fadeIn("slow"); } 

    2 answers 2

    As I understand you have the jQuery library connected, in fact, through it you can send requests a lot easier.

    Example:

    This line:

     $.ajax({ type: "POST", url: "/stat/zayavka.php", data: "data="+data, success: function(html) { $("#result").empty(); $("#result").append(html); } }); 

    Replace with this:

     $.post('/stat/zayavka.php',{peremennaya:'value'},function(data){ if(data){ $("#result").empty(); $("#result").append(html); } else{ alert('Нет ответа'); } }); 

    Explanation:

    1. peremennaya - Variable that is sent.
    2. value - what exactly we send.
    3. data - answer

    Try :)

      1) zayavka.php, an hour does not wait? - not*.
      2) Does ajax request occur at all? (the easiest way to check is to insert alert ('123456') before and after $ .ajax ();)

      • Not. There there is a check on the correctness of the entered data and further distribution, etc. Here is the beginning of the file: if (ereg ("^ [AZa-ya] + $", $ _ POST ["firstname"]) == false) $ error_flag = 1; if (ereg ("^ [A-Yaa-I] + $", $ _ POST ["data"]) == false) $ error_flag = 1; - Monkrif