简体   繁体   English

如何使用html和ajax在另一个页面中发送数据

[英]how to send data in another page with html and ajax

i'm starting delevope android application with phonegap as you may know i can't use php file in front-end of my app, so i have a list that create dynamic when user click on the each link go to the singers_category.html and base of the the $genre_id i want load group of singers on singers_category.html ; 我正在用phonegap启动delevope android应用程序,因为您可能知道我不能在我的应用程序前端使用php文件,因此我有一个列表,当用户单击每个链接转到singers_category.html时,它会创建动态列表。我要在singers_category.html上加载歌手组的$genre_id singers_category.html i'm try using QueryString but i'm think i can't using QueryString in html page; 我正在尝试使用QueryString但我认为我无法在html页面中使用QueryString so this is my code of php handler: (i'm using switch case to using multiple handler in one page) 所以这是我的php处理程序代码:(我正在使用切换用例以在一页中使用多个处理程序)

<?php
include('db_inc.php');
$functionId=$_GET['functionId'];
echo "$functionId <br>";
switch($functionId){
    case "":
    $singer_id =$_POST['last_items'];
    $result = $connection->query("SELECT * from genre")or die($connection->error);
        while($row = $result->fetch_object()){
            $genre_name = $row->genre_name;
            $genre_id = $row->genre_id;
            echo "<li><a href='singers_category.html?$genre_id >$genre_name</li>";
            }
            $connection->close;
            break;
    }


?>

my question is:how to access specific $genre_id with ajax and html and one php handler in singers_category.html 我的问题是:如何使用ajaxhtmlsingers_category.html一个php处理程序访问特定的$genre_id singers_category.html

You would capture the item to be returned in JS like this: 您将像这样捕获要在JS中返回的项目:

function CloseWindow() {
        var hidchg = document.getElementById('<%=hidItemsChanged.ClientID %>');
        window.opener.TransDataChange(hidchg.value);
        window.open('', '_self', ''); window.close();
        return false;
    }

and capture in sending page like this: 并捕获在发送页面中,如下所示:

function TransDataChange(changeMade) {
if (changeMade == "true") {
    //..do something    }

} }

The format that you use is 您使用的格式是

 echo "<li><a href='singers_category.html?genre=" . $genre_id . "'>" . $genre_name . "</a></li>";

After this, in your code you can read that by: 此后,您可以在代码中通过以下方式读取该信息:

$_GET['genre']

对于此问题,我们可以使用以下脚本: http : //jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html

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

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