简体   繁体   中英

post data by ajax jquery

i want to save data in database by a button click.here is my code,in Firefox it do not work it show empty alert and data do not saved in table.

    $("#Save").click(function () {  
       var price = $("#price").val(); 
       var agent_1_id= $("#agent_1_id").val();
       var type = $("#type").val();
    $.post("ajax_files/myDeals.php",
             { 
              price: price,
              agent_1_id: agent_1_id,type:type
              },
            function(data) {
                alert(data);
      });           
});

click event fires and this function calls. Here is code on myDeals.php to save in table..

$price = $_REQUEST['price']; 
$agent_1_id = $_REQUEST['agent_1_id'];
$type = $_REQUEST['type'];
mysql_query('insert query here');

echo "Saved Successfully ";//this is not alerted?

Try the sample sending the data as an object:

function end_incident() {
    $.ajax({
       type: "POST",
       url: "http://www.example.co.uk/erc/end_incident.php",
       data: { name: "Daniel", phone: "01234123456" },
       success: function(msg){ 
            alert('Success!');
       }
    });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM