jquery - How to post variable into controller (PHP+AJAX+MVC) -


i'm trying post variable php controller ajax:

$(".inp_pr").keypress(function(f) { if (f.which == 13) { datastring = 'qwe'; $.ajax({ type: "post", url: "/prwrk/", data: 'datastring=' + datastring, success: function(data) { alert('<?php echo($data)?>'); } }); event.preventdefault(); } }); 

controller source:

 function action_index()  {  $data=$_post['datastring'];  $this->view->generate('prwrk_view.php', 'template_view.php',$data);  } 

ajax posts variable success, controller has no it. think, not correct url, not working full url controller file.

router source:

class route { static function start() {  $controller_name = 'main'; $action_name = 'index';  $routes = explode('/', $_server['request_uri']);  if ( !empty($routes[1]) ) {        $controller_name = $routes[1]; }     if ( !empty($routes[2]) ) {     $action_name = $routes[2]; }    $model_name = 'model_'.$controller_name; $controller_name = 'controller_'.$controller_name; $action_name = 'action_'.$action_name;    $model_file = strtolower($model_name).'.php'; $model_path = "application/models/".$model_file; if(file_exists($model_path)) {     include "application/models/".$model_file; }   $controller_file = strtolower($controller_name).'.php'; $controller_path = "application/controllers/".$controller_file; if(file_exists($controller_path)) {     include "application/controllers/".$controller_file; } else {      route::errorpage404(); }   $controller = new $controller_name; $action = $action_name;  if(method_exists($controller, $action)) {      $controller->$action(); } else {      route::errorpage404(); }  }  function errorpage404() { $host = 'http://'.$_server['http_host'].'/'; header('http/1.1 404 not found'); header("status: 404 not found"); header('location:'.$host.'404'); } } 

how post variable php controller correct?

change this

data:$("#formid").serialize(), 

and submits normal form submit through ajax


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -