1

我正在尝试将一些数据发布到将执行 mysql 插入的函数。没什么好看的。但我可以让事情正常工作,我的问题是我应该告诉 jQuery 发布到哪里,它会尊重 php 包含的内容吗?

这就是我所拥有的

include_once 'modules/interviews/helper.php';

if($link == 'my_interviews'){
   include_once 'modules/interviews/my_interviews.php';
} elseif($link == 'interview_panel'){
   include_once 'modules/interviews/interview_panel.php';
}

上面是我的index.php,在提交表单的页面加载

$('.addinote').click(function() {

var app = $(this).attr("data-app"),
user = $(this).attr("data-subi"),
txt = $('#' + app).val();

if(txt === ''){
alert('Whoops, did you enter something?');
}else{
   var  params = {};
   params['user_id'] = user;
   params['app_id'] = app;
   params['inote'] = txt;
   params['subinote'] = '1';

   $.post('http://localhost/gem/modules/interviews/index.php', params,            
       function(data){
           if(data){

           }
           else{
              alert('Whoops, there was a problem, please try again!');
           }
    });
}

helper.php 包含这个...

if(isset($_POST['subinote'])){


    $apply->inote();

} 

并且该类包含这个....

function inote(){

$query = "INSERT INTO `app_notes` (`user_id`, `application_id`, `inote`) 
          VALUES ('{$_POST['user_id']}', '{$_POST['app_id']}', 
          '{$_POST['inote']}')";    

$GLOBALS['DB']->insertQuery($query);

}

我应该在哪里发帖?

4

1 回答 1

1

如果这是读取 $_POST 变量的那个,您应该发布到 index.php。

此外,您应该使用相对 url,例如,如果 helper.php 与您使用的 html 文件位于同一目录中,./index.php或者只是index.php作为您的帖子 url。我更喜欢前者,因为它明确说明了您的意图。

于 2012-07-14T17:56:29.647 回答