简体   繁体   中英

Update data sent by php form using ajax

I can't really figure out this problem , let's say that on the page there is a form with one input in it , if you submit the form then the text that you save will be sent to the database and stored now , i would like to get user location:

Longitude Latitude

whenever he submits the form , now I found that it's better to get the location using Javascript and then send it to the server using AJAX so basically when i submit the form the text of input is stored in the database and , I marked the submit button with id "submit" and I want to use ajax with jquery so:

$.ajax({ 
    url:'update_the_last_form_submit_data.php', 
    type:'POST', 
    data:{lat:lat,lat:lat}
    success:, 
    error: 
});

so what i want to do is , when ever the user submits the form , ajax will add the current longitude and latitude to the MySQL query which is being sent to database

and finally the table will look like this :

Time------------User Input--------Latitude---------Longitude
xx-xx-xx--------What you tiped----Detected longitude-------detected latitude

edit:

I don't know how do i do it

basically i have a click function with the ajax code but I don't know when i send the ajax request how do i know which row is the one that was just sent by me to php

$("#submit").click(function(){
   $.ajax({ 
        url:'update_the_last_form_submit_data.php', 
        type:'POST', 
        data:{lat:lat,lat:lat}
        success:, 
        error: 
    });


});

好的,所以我可能会提出解决方案,当用户提交表单时,我会将会话用户名保存在数据库中,并且当触发ajax代码时,它将更新当前用户的会话所做的最后一条记录

You just need to pick up the "lat" POST variable in your PHP and then use it. Sounds like you already know how to write to the database so that part is already solved. When you send the request to 'update_the_last_form_submit_data.php' there will be a variable $_POST["lat"] which you can use in the normal way.

Incidentally there's an error in your data variable - lat is defined twice. I suspect you want something like:

data: {lat:lat,long:long}

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