Javascript php jquery对话框在关闭按钮时为变量赋值
我需要帮助分配一个在php文件中使用的变量。我有一个功能,可以在jquery对话框窗口中显示GoogleBooks搜索结果。这很好(有一个小故障我正在分别处理)。我现在要做的是为变量赋值,以便在php文件中进一步使用。例如,指定书名,以便我可以在php文件中以单独的形式显示书评 这是我的密码:Javascript php jquery对话框在关闭按钮时为变量赋值,javascript,php,jquery,variable-assignment,Javascript,Php,Jquery,Variable Assignment,我需要帮助分配一个在php文件中使用的变量。我有一个功能,可以在jquery对话框窗口中显示GoogleBooks搜索结果。这很好(有一个小故障我正在分别处理)。我现在要做的是为变量赋值,以便在php文件中进一步使用。例如,指定书名,以便我可以在php文件中以单独的形式显示书评 这是我的密码: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <t
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="//whosgotbooks.com/jquery/jquery-ui-1.10.4.custom.css">
<script src="//whosgotbooks.com/jquery/jquery-1.10.2.js"></script>
<script src="//whosgotbooks.com/jquery/jquery-ui-1.10.4.custom.js"></script>
</head>
<body>
<div id="dialog" title="Google Books Search Results" style="display:none;">
<script>
//$("#searchForm").on("submit", function() { return false; });
$(function() {
$( "#dialog" ).dialog({
height: 550, width: 450});
$("input[type='btn']").click(function(){
var book_title = '';
switch(this.returnvalues$i) {
case 'btn':
book_title = "$item['volumeInfo']['title']";
}
$('.$book_title').html(book_title);
});
$( ".btn" ).click(function(){
$( "#dialog" ).dialog( "close" );
});
});
</script>
<strong><p style="font-size: 16px; text-align: center";>Top 10 Results for "<?php echo @$_POST['q']; ?>"</p></strong>
<strong><p style="font-size: 14px; text-align: center";>choose a book to select as your topic</p></strong>
<table style="width:400px">
<col width="325">
<col width="75">
<?php foreach ($data['items'] as $item) { ?>
<?php for($i =1; $i <11; $i++) { ?>
<tr>
<td>
<strong><u><div style="font-size: 14px";><?php printf($item['volumeInfo']['title'])?></u></div></strong>
<strong>Author: </strong><?php printf( $item['volumeInfo']['authors'][0])?><br />
<strong>Published: </strong><?php printf( $item['volumeInfo']['publishedDate']); ?><br />
<strong>Page(s): </strong><?php printf( $item['volumeInfo']['pageCount']); ?><br />
<strong>Publisher: </strong><?php printf( $item['volumeInfo']['publisher']); ?><br />
<strong>Category: </strong><?php printf( strtolower($item['volumeInfo']['printType']).', '.strtolower($item['volumeInfo']['categories'][0])); ?>
<strong>ISBN: </strong><?php printf( $item['volumeInfo']['industryIdentifiers'][0]['identifier']); ?></td>
<td><p><input type="submit" method="post" name="selectbook" value="Select" class="btn" id="returnvalues$i"/></p>
<img src="<?php printf( rawurldecode($item['volumeInfo']['imageLinks']['smallThumbnail'])); ?>" />
</td>
<tr><td style="width:420px"><p><strong>Description: </strong><?php printf( $item['volumeInfo']['description']); ?><br /></p></td>
</tr>
</tr>
<?php } } }
else {
?>
<p><strong>Sorry, there were no results</strong></p>
<?php }
/* for testing purposes show actual request to API - REMOVE when finished
$apiRequest = $url;
echo '<p>API request: '.$apiRequest.'</p>'; */ ?>
</table>
</div>
</body>
</html>
<?php
else: //show form and allow the user to check for Google Book search results
?>
<p><form id="searchForm" name="searchForm" method="post">
<fieldset id="searchBox">
<label>Search for a Book:</label>
<input class="text" id="q" name="q" type="text" value="Powered by Google" onfocus="this.value=''; this.onfocus=null;" />
<select id="type" name="type" size="1">
<option selected value="all">Book Title</option>
<option value="isbn">Books by ISBN</option>
<option value="lccn">Books by LCCN #</option>
<option value="oclc">Books by OCLC #</option>
</select>
<input class="submit" id="searchForm" name="submit" type="submit" value="Search" />
</fieldset>
</form></p>
您可以使用ajax将这些JavaScript变量发布到一个单独的PHP脚本中,该脚本返回结果的HTML,如果可以刷新页面,也可以将这些变量发布到页面本身。@RodneyGolpe,谢谢,但我不擅长编码来实现您的建议。你能帮我写一些特定的代码吗?我是那种搜索示例然后修改它们以适合我的代码的人。啊,对不起,这对我来说太复杂了,我现在无法处理。我打赌你会到达那里;)@RodneyGolpe,我明白。我刚刚对我的帖子进行了编辑,并添加了使用ajax传递变量的尝试。如果你有时间,请看一看。对于url,是否需要使用“http://”包含完整的url?我对ajax代码中的许多其他内容不太清楚。我会继续找的。谢谢你迄今为止的帮助。
<script>
//$("#searchForm").on("submit", function() { return false; });
$(function() {
$( "#dialog" ).dialog({
height: 550, width: 450});
$("input[type='btn']").click(function(){
var book_title = '';
switch(this.returnvalues$i) {
case 'btn':
book_title = "$item['volumeInfo']['title']";
}
$('.$book_title').html(book_title);
});
$( ".btn" ).click(function(){
$( "#dialog" ).dialog( "close" );
});
});
</script>
$(function() {
$( "#dialog" ).dialog({
height: 550, width: 450});
$( ".btn" ).click(function(){
var book_title = $(this).attr('returnvalues$i');
$.ajax({
type: "POST",
url: 'book-search-google.php',
data: "book_title=" + book_title,
success: function(data)
{
alert("success!");
}
});
$( "#dialog" ).dialog( "close" );
});
});