angularjs将url参数传递给php [英] angularjs pass url param to php

查看:111
本文介绍了angularjs将url参数传递给php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用angularjs路由将URL参数传递给php变量?

how to pass URL parameter to php variable using angularjs routing?

这是routing_script.js:

This is routing_script.js :

var scotchApp = angular.module('HRModuleApp', ['ngRoute']);

scotchApp.config(function($routeProvider) {
    $routeProvider

        .when('/', {
            templateUrl : 'pages/home.html',
            controller  : 'mainController'
        })
        // route for the home page
        .when('/home', {
            templateUrl : 'pages/home.html',
            controller  : 'mainController'
        })
    // route for the contact page
        .when('/public_profile:user_id', {
            templateUrl : 'pages/public_profile.php',
            controller  : 'contactController'
        })

        // route for the contact page
        .when('/add_user', {
            templateUrl : 'pages/add_user.html',
            controller  : 'contactController'
        });
});

我还应该添加什么?如何将id_user参数从url转发到php变量...这样php可以执行一些sql ...

what else should I add to this? how to forward id_user parameter from url to a php variable... so php can execute some sql...

我还读到了类似这样的东西的角不是...但是我需要它...而且我迫切需要...

I also read about how angular isnt for something like this... but I need it... and I need it urgently...

谢谢!

以下是$ term变量,它需要php文件中的url参数:

here is the variable $term that needs that url parameter in php file:

<?php
$term = mysql_real_escape_string($_REQUEST['user_id']);

推荐答案

这是触发onclick事件的javascript ...单击数据表中的一行...我得到的链接看起来不错,但是php脚本没有得到该网址

this is the javascript that triggers onclick event... a click on a row in datatable... the link I get looks fine, but php script doesnt get that url

    $(document).ready(function() {

    $(function(){
        $.ajax({
            url: 'http://localhost/hrmodel/public/pages/employees_datatables.php',
            data: {},
            dataType: 'json',
            success: function (data) {

            // Check if received data is indeed JSON Object and not a string

                if (data.substring) {
                    console.log('is string');
                } else{
                    console.log('is not string');
                }

            // Setup for individual column search - add a text input to each footer cell

                $('#employees tfoot th').each( function () {
                    var title = $('#employees thead th').eq( $(this).index() ).text();
                    $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
                } );

            // Initialize Datatable

                var table = $('#employees').DataTable( {
                   "bProcessing": true,
                   "bSearchable" : true,
                   "bSortable" : true,
                   "bFilter": true,
                   "bInfo": true,
                   "bPaginate" : true,
                   "data" : data,
                   "columns": [
                        { "data": "korisnik_id",
                            "visible": false,
                            "searchable": false
                        },
                        { "data": "ime" },
                        { "data": "prezime" },
                        { "data": "3" },
                        { "data": "naziv" }
                    ]
                } );

            // Apply the search for each column

                table.columns().eq( 0 ).each( function ( colIdx ) {
                   $( 'input', table.column( colIdx ).footer() ).on( 'keyup change', function () {
                       table
                           .column( colIdx )
                           .search( this.value )
                           .draw();
                   } );
                } );

           // Highlighting rows

                var lastIdx = null;

               $('#employees tbody').on( 'mouseover', 'td', function () {
                   var colIdx = table.cell(this).index().column;

                   if ( colIdx !== lastIdx ) {
                       $( table.cells().nodes() ).removeClass( 'highlight' );
                       $( table.column( colIdx ).nodes() ).addClass( 'highlight' );
                    }
                } )
                .on( 'mouseleave', function () {
                   $( table.cells().nodes() ).removeClass( 'highlight' );
                } );

            // Send user_id of selected row to PHP script

                $('#employees tbody').on( 'click', 'tr', function () {
                   var id = table.row( this ).data().korisnik_id;
                   $(this).addClass('chosenUser');
                   window.location = '#/public_profile.php?user_id=' + id;
/*
                   $.ajax({
                        type: 'POST',
                        url: 'http://localhost/hrmodel/public/pages/public_profile.php',
                        data: { user_id : id },
                        dataType: 'json',
                        success: function (data) {}
                    } );
*/
                } );

            } // End of ajax : success
        }); // End of .ajax request
    }); // End of function()
}); // End of document.ready()

这篇关于angularjs将url参数传递给php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆