嗨,我有一个jquery内容动画,除了内容加载之外,其他所有功能都正常。
$(function() {
var newHash = "",
$mainContent = $("#main_content"),
$pageWrap = $(".big_col"),
$main_menu = $("a.main_menu"),
baseHeight = 0,
$el;
$pageWrap.height($pageWrap.height());
baseHeight = $pageWrap.height() - $mainContent.height();
$("body").delegate("a.main_menu", "click", function() {
window.location.hash = $(this).attr("href");
return false;
});
$(window).bind('hashchange', function(){
newHash = window.location.hash.substring(1);
if (newHash) {
$mainContent
.fadeOut(200, function() {
$mainContent.hide(function() {
$(".loader").show();
var page = newHash.replace(/\..+$/, '');
var page = page.replace(/!/, '');
var data = 'page=' + page;
$.ajax({
url: "main_content/action.php",
type: "POST",
data: data + "&request=ajax",
cache: false,
success: function …Run Code Online (Sandbox Code Playgroud) mysql_query("INSERT INTO fatture_servizi (id, rif_fattura, servizio, quantita, prezzo_unitario, prezzo_servizio, iva) VALUES ('NULL', '$invoice_rif', '{$services_global[$i]['service']}', '{$services_global[$i]['amount']}', '{$services_global[$i]['unit_price']}', '{$services_global[$i]['service_price']}', '{$services_global[$i]['service_vat']}')");
Run Code Online (Sandbox Code Playgroud)
我需要把它放在像php这样的循环中
$c=count($services);
for($i=0;$i<$c;$i++){
mysql_query("INSERT INTO fatture_servizi (id, rif_fattura, servizio, quantita, prezzo_unitario, prezzo_servizio, iva) VALUES ('NULL', '$invoice_rif', '{$services_global[$i]['service']}', '{$services_global[$i]['amount']}', '{$services_global[$i]['unit_price']}', '{$services_global[$i]['service_price']}', '{$services_global[$i]['service_vat']}')");
};
Run Code Online (Sandbox Code Playgroud)
问题是它只将数据的第一个值插入db而不是每个值.
$ services_global数组看起来像这样但它可能会改变,因为它来自一些动态生成的输入(进入主页面,你可以添加任意数量的服务).
Array ( [0] => Array ( [service] => Hostess [amount] => 1 [unit_price] => Eu 120,00 [service_price] => Eu 120,00 [service_vat] => 21 ) [1] => Array ( [service] => Pullman [amount] => 4 [unit_price] => Eu …Run Code Online (Sandbox Code Playgroud) 嗨,我想将一个dinamically生成(与PHP)HTML代码存储到一个变量,并能够将其作为对ajax请求的回复发送.假设我随机生成一个表格,如:
<?php
$c=count($services);
?>
<table>
<?php
for($i=0; $i<$c; $i++){
echo "<tr>";
echo "<td>".$services_global[$i][service] ."</td>";
echo "<td>".$services_global[$i][amount]."</td>";
echo "<td>€ ".$services_global[$i][unit_price].",00</td>";
echo "<td>€ ".$services_global[$i][service_price].",00</td>";
echo "<td>".$services_global[$i][service_vat].",00%</td>";
echo "</tr>";
}
?>
</table>
Run Code Online (Sandbox Code Playgroud)
我需要存储所有生成的html代码(和其余的)并将其作为json编码变量回显,如:
$error='none';
$result = array('teh_html' => $html, 'error' => $error);
$result_json = json_encode($result);
echo $result_json;
Run Code Online (Sandbox Code Playgroud)
我可以生成一个html文件然后用以下内容读取:
ob_start();
//all my php generation code and stuff
file_put_contents('./tmp/invoice.html', ob_get_contents());
$html = file_get_contents('./tmp/invoice.html');
Run Code Online (Sandbox Code Playgroud)
但这听起来是错的,因为我不需要生成代码,只是将其作为对ajax请求的回复发送到我的主页面,这将浪费资源.有什么建议?