2012-06-02 107 views
0

我有一个jquery函数,用于检索用户在数据库表中点击的信息。用户可以选择鼠标悬停时突出显示的十行中的任何一行,以及当用户单击突出显示的行时函数检索它并将其放入文本框中。然后,如果用户提交此购买请求,我想在订单表单的下一页上回显文本框。从URL获取变量

下面的代码运行良好,直到我尝试从url检索信息。我可以看到它在URL中传递到下一页,但尝试两天后我无法检索它。我不知道该从哪里出发。有人可以看看这个,看看我没有正确编码或做错了什么。 我抄下来适用的代码...

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript"> 


$(document).ready(function(){ 
    $("table tr").click(function(){ 
     $("#txttread").val($.map($(this).children('td:not(:eq(7))'), function (item) { return $(item).text() }).join(' - ')); 
    }); 
}); 


$(document).ready(function() { 

    $('.pickme tr').not(':first').hover(
     function() { $(this).addClass('highlight'); }, 
     function() { $(this).removeClass('highlight'); } 
    ).click(function() { 
     $('.selected').removeClass('selected'); 
     $(this).addClass('selected').find('input').attr('checked','checked'); 
    }); 
}); 


</script> 
</head> 
<body> 
<form action="Order.html" method="GET" name="myform2" /> 



<div> 
<div style="text-align:left height:250px;"> 
<DIV STYLE="font-family: Arial Black; 
color: black; font-size: 20pt;"> 

Select from inventory below:<br/><input type="text" style="width:500px; height:35px;" rows="1" STYLE="font-family: Arial Black; 
color: red; font-size: 20pt;" name="txttread" id="txttread" DISABLED /></div></div></div> 
<div> 
<div style="text-align:center;"> 



<br/><input type="button" button id="getone" name="getone" value="Submit your request for purchase" onclick="window.location.href = 'http://localhost/order.html?txttread='+ ($('#txttread').val())"><br/><hr/> 
</body> 
</html> 

下一个页面上的网址是....

http://localhost/order.html?txttread=Firestone - All Season - FR-710 - 225/60/16 - 4 - 3 - 60.00 

回答

1

这可能无法完全回答你的问题,但考虑到这一点:

window.location.href = 'http://localhost/order.html?txttread='+ ($('#txttread').val()) 

当你传递参数您应该应用适当的转义:

window.location.href = 'http://localhost/order.html?txttread=' + encodeURIComponent($('#txttread').val()); 

从HTML网页访问的txttread值:

由于这里找到:https://stackoverflow.com/a/901144/1338292

+0

我仍然无法呼应了从订单表格上的网址的任何信息。 – Urob

+0

@Urob的事情是,我没有看到任何PHP代码发布:) –

+0

@Urob你想从HTML或PHP btw访问'txttread'吗? –

1

我认为这与没有被正确编码的URL做。你在哪里追加$('#txttread').val()最后一行,你应该encodeURIComponent()把它包:

<input type="button" 
     button id="getone" 
     name="getone" 
     value="Submit your request for purchase" 
     onclick="window.location.href = 'http://localhost/order.html?txttread=' + encodeURIComponent($('#txttread').val());">