douchen4534
2015-10-07 20:55
浏览 300
已采纳

使用AJAX将变量传递给Div

ORIGINAL POST: Not sure why I am having such a hard time grasping this but I am creating a page that executes a query to list a set of records per a user. I am wanting to create a div that shows the details of a select record from the list. I am attempting to load that record with the following:

    $(document).ready(function(){
    // load index page when the page loads
    $("#form").load("tm-reserves-form.php");
    $("#record").click(function(){
    // load home page on click
        $("#form").load("tm-reserves-form-test.php?ContactID"+$ContactID);
    });
});

Initial form loads but I can not get my .click function to work using the URL parameters.

How can I pass the url parameter from my current query into a div that loads an external page and executes a second query based on that url paramenter (primary id)?

Thanks in advanced for helping me out!

EDIT POST: Found solution, but another issue has arisen.

So I took a crash course this weekend on ajax and I found a working solution here:

    $(document).ready(function(){
    // load index page when the page loads
    $("#form").load("tm-reserves-form.php");
    $("#record").click(function(){
    // load home page on click
        var ContactID = document.getElementById('ContactID').value;
        $("#form").load("tm-reserves-form.php", {"ContactID": ContactID});
        });
    });

So with this example, when the page loads the div form is loaded with a default page. With a click function on the label #record the div #form is than loaded with a parameter of ContactID that is a string value inside of #ContactID. All that seems to work very well (even passes the parameter correctly).

The issue now is that it is only allowing me to pass the first record to my div. Any thoughts on what I need to implement next? I originally thought it was to clear the var but that didn't work either.

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

ORIGINAL POST </ em>:不知道为什么我很难抓住这个但是我 我正在创建一个页面,执行查询以列出每个用户的一组记录。 我想创建一个div,显示列表中选择记录的详细信息。 我试图用以下内容加载该记录:</ p>

  $(document).ready(function(){
 //页面加载时加载索引页
 $  (“#form”)。load(“tm-reserve-form.php”); 
 $(“#record”)。click(function(){
 //加载主页点击
 $(“  #form“)。load(”tm-reserve-form-test.php?ContactID“+ $ ContactID); 
}); 
}); 
 </ code> </ pre> 
 
 <  p>初始表单加载但我无法使用URL参数使我的.click函数工作。</ p> 
 
 

如何将当前查询中的url参数传递给加载外部的div 页面并基于该url参数(主要ID)执行第二个查询?</ p>

感谢先进的帮助我!</ p>

编辑 发布</ strong>:找到解决方案,但又出现了另一个问题。 </ p>

所以我本周末在ajax上参加了一个速成课程,我在这里找到了一个有效的解决方案:</ p>

  $(document).ready(  function(){
 //页面加载时加载索引页
 $(“#form”)。load(“tm-reserve-form.php”); 
 $(“#record”)。click(  function(){
 //在主页上加载主页
 var ContactID = document.getElementById('ContactID')。value; 
 $(“#form”)。load(“tm-reserves-form.php”  ,{“ContactID”:ContactID}); 
}); 
}); 
 </ code> </ pre> 
 
 

因此,在本例中,当页面加载div格式时 加载了默认页面。 使用标签#record上的click函数,div #form将加载一个ContactID参数,该参数是#ContactID中的字符串值。 所有这些看起来效果都很好(甚至正确传递参数)。 </ p>

现在的问题是它只允许我将第一条记录传递给我的div。 关于我接下来要实施什么的想法? 我最初认为这是清除var但是也不起作用。</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题