duan198811 2017-02-14 11:44
浏览 59
已采纳

通过Angular视图的URL发送ID

I am using Angular to create my single page views but I am struggling to pass an ID from an sql select via the URL.

I have created my view like so:

var app = angular.module("myApp", ["ngRoute"]);

    app.config(function($routeProvider) {
        $routeProvider
        .when("/jobSingle", {
            templateUrl : "jobSingle.php"
        });    
    });

Works great shows me the correct page. I am TESTING data so this is open to SQL injection but I am playing around with Angular so don't freak out - I am linking to the single view page from another view like so:

$sql = "SELECT * FROM jobs";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) { // Start while
        echo $row['title'];
        echo '<a href="#jobSingle?id=' . $row['id'] . '">View Job</a>';
        ?>

        <div class="lightboxHide animated fadeInUp">
            <div id="mylightbox">
                <?php echo $row['title']; ?>
            </div>
        </div>
    <?php
    } // End while
} else {
    echo "0 results";
}

So where I have echo '<a href="#jobSingle?id=' . $row['id'] . '">View Job</a>'; it appears to be the correct url and it opens the correct view but when I GET the id form the URL and var dump it i get nothing...

$jobId = $_GET['id'];
var_dump($_GET);

$sql = "SELECT * FROM jobs WHERE id = '$jobId'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) { // Start while
        echo $row['title'];
    } // End while
} else {
    echo "0 results";
}

My var dump just simply shows....

array(0) { } 0 results

Aswell when I do a var_dump on the $_GET I get a NULL value returned... Its almost like the url is being ignore, well the Id is at least...

Is this even possible OR am I missing the point here? I am learning angular as I work with Php primarily I wanted to know if this was do able?

  • 写回答

1条回答 默认 最新

  • dp152153 2017-02-14 16:33
    关注

    Href #jobSingle?id=... in your <a></a> tag sets <fragment> part of a URL. When you open a website your browser does not include <fragment> part of a URL in its request.

    To see the difference just swap <query> and <fragment> parts in your ULR to fulfill correct URL scheme. For example: ?id=1#jobSingle.

    Here is the common URL syntax to clarify what I'm talkign about:

    <scheme>://<user>:<password>@<host>:<port>/<path>?<query>#<fragment>
    

    Everything that goes after # mark in URL is treated like a fragment.

    RFC 1738 and RFC 3986 contain full explanation for raised topic.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝