dongmufen8105 2015-06-26 22:04
浏览 21

通过Javascript从html更改为html保留一个变量

working on my first webapp, having conflict with this, I hope there is an easy solution :/

I have this profile.html that only have html structure, I fill it dynamically with php and my database, all cool so far.

I have another one search-results.html, which with a bunch of queries 'Post' start building the results depending on the filters... all good so far.

Now the issue, I need to be able to send to my profile.html the right id when the user clicks on a product from the search-results.html, I gave each product a data-product id, the problem is that im stuck, because I just dont know how to open the profile.html when product clicked and somehow let the profile.html which product was actually clicked... here is some code just to make it easier to understand my situation here...

profile.html

$(document).ready(function(){
      var num=(Math.random()*3+1);
      num=num|0;
      num=num.toString();
      var n=num.toString();

        ajaxPost("Path/get.php", { id : n}, function(result){
          var json=JSON.parse(result);
          if(json.error==0){
          console.log(json);
          $('img#fotoProfile').attr('src',json.response.profile_picture);             
          var nombreFoodtruckConCiudadyPais = json.response.name + "   <span class='subtitle'>@" + json.response.cities + "</span>";
          $('h2.profile-name').html(nombreFoodtruckConCiudadyPais);
          $('#foodtruckName').html(json.response.name);
          $('div#descripcion p#descripcionText').html(json.response.description);
          $('a#emailText').attr('href',json.response.mail);
          $('div#email a#emailText').html(json.response.mail);
          $('div#rating p#ratingText').html(json.response.rating);
          $('div#categoria p#categoriaText').html(json.response.category);
          var origen = json.response.cities + ', ' + json.response.states + ', ' + json.response.countries;
          $('div#origen p#origenText').html(origen);
          $('div#telefono p#telefonoText').html(json.response.phone);
        }else{
          alert("Foodtruck Not Found");
        }
        });

search-results.html on click handler...

$(document).on('click', '[data-idFT]', function(){ 
            var x=($(this).data('idft'));
            //What do I do here?
         });

Basically im stuck right there. My x should be my n on my profile.html ajaxPost id : n...

I hope I can get some aid, im new to webapps... thanks in advance.

  • 写回答

2条回答 默认 最新

  • dongnigeng1295 2015-06-26 22:09
    关注

    You need to add 'x' as a parameter to the profile.html URL i.e profile.html&idft=x

    $(document).on('click', '[data-idFT]', function(){ 
      var x=$(this).data('idFT');           
      var url = "profile.html?idft="+x;    
      window.location.href = url;
    })
    

    If retrieving the parameter on profile.html using JavaScript use a technique like some on this post How to get the value from the GET parameters?

    Or it sounds like you probably need to use it in PHP if your accessing the DB then all you need is:

    <?php
    echo htmlspecialchars($_GET["idft"]);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了