简体   繁体   English

请用jQuery.post帮助我。 我的脚本没有给出错误,也没有发布表单字段

[英]Please help me with jQuery.post. My script not giving an error nor posting form fields

I cant not figure out why this script doesn't work. 我不知道为什么这个脚本不起作用。 It has to do with something within the AJAX POST script/function. 它与AJAX POST脚本/函数中的某些内容有关。 Right now, when I hit submit on my form, it should pass the form values to ajax_profile.php page. 现在,当我在表单上单击“提交”时,它将把表单值传递给ajax_profile.php页面。 It is not sending / posting form fields data. 它不是发送/发布表单字段数据。 Please help me figure out the problem. 请帮助我找出问题所在。 Here is my Javascript code: 这是我的Javascript代码:

<script type="text/javascript">

$(document).ready(function(){

    $('Buddie_profile').submit(function () {

            $.post('ajax_profile.php', $(this).serialize(), function(data) {

                            if(data.success){ 

                                    $("body").showMessage({

                                        'thisMessage':  [data.message],

                                        'autoClose':    true,

                                        'className':    'tooltip',

                                        'delayTime':    8000,

                                        'displayNavigation':    false

                                    });

                                }else{

                                    $("body").showMessage({

                                        'thisMessage':  [data.message],

                                        'autoClose':    true,

                                        'className':    'tooltip',

                                        'delayTime':    8000,

                                        'displayNavigation':    false

                                    });

                                }

                            },'json');

                return false;
            });
});

here is my php file code for ajax_profile.php: 这是我的ajax_profile.php的php文件代码:

require('include/conn.php');


                                    $success= mysql_query("UPDATE birthbuddie SET 

                    Fname='".$_POST['FirstName']."',

                    Lname='".$_POST['SecondName']."',

                    Surname='".$_POST['Surname']."',

                    Dayofbirth='".$_POST['DayofBirth']."',

                    Monthofbirth ='".$_POST['MonthofBirth']."'

                    Yearofbirth='".$_POST['YearofBirth']."',

                    Ss='".$_POST['ss']."',

                    Mm='".$_POST['mm']."',

                    Hh='".$_POST['hh']."',

                    Countryofbirth='".$_POST['CountryofBirth']."',

                    Cityofbirth='".$_POST['CityofBirth']."',

                    Personalmsg='".$_POST['PersonalMessage']."',

                    WHERE BBId='".$_SESSION['userid']."'");


    if($success){

            $data['success']=true;
            $data['message']='You have updated changes successfully';

        }else{

            $data['success']=false;
            $data['message']='Update was not successful. Try again';
        }

        echo json_encode($data);    

?> ?>

You're not properly serializing the form data. 您没有正确序列化表单数据。 You're not quoting the string values. 您没有引用字符串值。 You're not URI-encoding the form data. 您不是对表单数据进行URI编码。 The way as you collected the form data may end up in a corrupt JSON object. 收集表单数据的方式可能最终会损坏的JSON对象。 This should have error'ed in the JavaScript console. 这在JavaScript控制台中应该有错误。 You should have noticed this error if you paid attention to the JavaScript console in your browser (press F12 in Firebug/Chrome/IE9). 如果您注意浏览器中的JavaScript控制台(在Firebug / Chrome / IE9中按F12),您应该已经注意到此错误。

Assuming that $('#Buddie_profile') refers a HTML <form id="Buddie_profile"> , then you should be serializing its data as follows: 假设$('#Buddie_profile')引用HTML <form id="Buddie_profile"> ,那么您应该按以下方式序列化其数据:

$.post('ajax_profile.php', $(this).serialize(), function(data) {
    // ...
});

Unrelated to the concrete problem, you've there some serious SQL injection hole . 具体问题无关 ,您有一些严重的SQL注入漏洞 If the enduser enters a valid partial SQL query string such as a (partial) DROP or TRUNCATE query in one of the input fields, then it'll get executed as well! 如果最终用户在输入字段之一中输入有效的部分SQL查询字符串,例如(部分) DROPTRUNCATE查询,那么它也将被执行! Use parameterized queries or at least mysql_real_escape_string() . 使用参数化查询或至少使用mysql_real_escape_string()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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