dtnpf35197
2016-09-17 20:24
浏览 46
已采纳

如何使用html和javascript获取并传递链接参数

i am wondering how to i pass an album ID# in the "include" url from ajaxbtn.php in this tab to the file that actually requests the URL

  1. home.php: HTML:<a href="javascript:;" id="album" class="ajax_tab">ALBUM ID #22</a>

JAVASCRIPT:

$( document ).ready(function GoAlbum() {
  //alert("pageload event fired!");
    $.ajax({
        url: 'assets/ajaxbtn.php',
        type: 'POST',
        data: {
        action:'album'
        },
        success: function(response){
            //alert(response);
            $("#content").html(response);
            $("#loading_image").hide();
            window.history.pushState("object or string", "Title", "/album");
        }
    }); 

now i have another files that handles the actions of the tabs

ajaxbtn.php:

if($_POST['action'] == 'album'){
   include("http://gypsychristiannetwork.com/assets/album.php?AlbumID=22");
    }

And this would be the content for album.php

if(isset($_GET['AlbumID'])){
    $AlbumID = $_GET['AlbumID'];
        echo '<h1>TEST: '.$AlbumID.'</H1>';
    }

as you can see here "id" is already being used by the html link, and href is set to javascript

so i'm not exactly sure what direction to go into to find a resolution to this

Thank you for your help

图片转代码服务由CSDN问答提供 功能建议

我想知道如何在此选项卡中的ajaxbtn.php的“include”网址中传递相册ID# 到实际请求URL的文件

  1. home.php: HTML:&lt; a href =“javascript:;” id =“album”class =“ajax_tab”&gt; ALBUM ID#22&lt; / a&gt;

    JAVASCRIPT: \ n

      $(document).ready(function GoAlbum(){
     // alert(“pageload event fired!”); 
     $ .ajax({
     url:'assets / ajaxbtn.php  ',
    键入:'POST',
     data:{
     action:'album'
    },
     success:function(response){
     // alert(response); 
     $(“#  content“)。html(response); 
     $(”#loading_image“)。hide(); 
     window.history.pushState(”object or string“,”Title“,”/ album“); 
    }  
    }); 
       
     
     

    现在我有另外一个处理标签操作的文件

    ajaxbtn.php:< / p>

      if($ _ POST ['action'] =='album'){
     include(“http://gypsychristiannetwork.com/assets/album.php?AlbumID=  22“); 
    } 
       
     
     

    这将是album.php的内容

      if(  isset($ _ GET ['AlbumID'])){
     $ AlbumID = $ _GET ['AlbumID']; 
     echo'&lt; h1&gt; TEST:'。$ AlbumID。'&lt  ; / H1&gt;'; 
    } 
       
     
     

    正如您所见,“id”已被html链接使用,并且href设置为javascript < / p>

    所以我不确定要找到解决方案的方向

    感谢您的帮助

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujiao3998 2016-09-17 20:34
    已采纳

    In your ajax call, you could add:

    id: 22
    

    So it would be:

    $.ajax({
            url: 'assets/ajaxbtn.php',
            type: 'POST',
            data: {
                action:'album',
                id: 22,
            },
            success: function(response){
                //alert(response);
                $("#content").html(response);
                $("#loading_image").hide();
                window.history.pushState("object or string", "Title", "/album");
            }
    

    And then in the PHP file:

    if($_POST['action'] == 'album'){
       include("http://gypsychristiannetwork.com/assets/album.php?AlbumID=".$_POST['id']);
    }
    

    And if you need the id coming from the HTML part:

    <a href="javascript:;" id="album" data-album-id="22" class="ajax_tab">ALBUM ID #22</a>
    

    And then, in the ajax call:

    data: {
        action:'album',
        id: $(this).attr("data-album-id"),
    },
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题