将PHP数组回应到Javascript文件/ FancyZoom弹出窗口

时间:2011-03-07 00:57:02

标签: php javascript json

点击我们的车辆详细信息页面上的“申请财务”按钮,在我们的网站上打开一个FancyZoom窗口,其中financeapp.js显示在窗口中显示的文件。我需要将一些变量(Year,Make和Model of Car)传递给此页面,以便它们显示在通过Vehicle Details页面弹出的Finance App窗口中。

Car Detail页面的代码如下:

<?php echo $product_array['make']; ?>

要在页面上显示Vehicle Make,在FancyZoom窗口上,我还希望让车辆回显。这可能与Javascript?可以这样,当打开Javascript窗口时,它会从详细信息页面获取车辆信息吗?

将PHP代码放入.js文件会导致语法错误。

这是financeapp.js的代码

$(document).ready(function(){       
    $('#content_outer').append('<div id="fancy_zoom_large_financeapp">\
            <form action="" id="finance-app-form" method="POST">\
            <H2>Apply for Finance</H2>\
<DIV id="mcms_contact">\
  <FORM id="ContactForm" encType="multipart/form-data" method="post" name="form1" action="/financeinsurance.html">\
    <INPUT type="hidden" name="type">\
    <p>Mandatory fields are indicated with a *</p>\
    <TABLE id="tablecontact">\
      <TBODY>\
        <TR>\
          <TH width="146">First Name *</TH>\
          <TD width="328"><INPUT id="firstname" size="50" name="firstname" AUTOCOMPLETE="OFF"></TD>\
          <TD width="311">&nbsp;</TD>\
        </TR>\
        <TR>\
          <TH>Surname *</TH>\
          <TD><INPUT id="surname" size="50" name="surname" AUTOCOMPLETE="OFF"></TD>\
          <TD>&nbsp;</TD>\
        </TR>\
        <TR>\
          <TH>Mobile *</TH>\
          <TD><INPUT id="mobile" size="50" name="mobile"></TD>\
          <TH rowspan="3">You are applying for finance for<br>the following vehicle: <br><img src ="images/car.jpg"><br>YEAR MAKE MODEL OF CAR<br>(Stock #STOCKNUMBER)</TH>\
        </TR>\
        <TR>\
          <TH>Postcode *</TH>\
          <TD><INPUT id="postcode" size="50" name="postcode" AUTOCOMPLETE="OFF"></TD>     \
        </TR>\
        <TR>\
          <TH>Email *</TH>\
          <TD><INPUT id="email_address" size="50" name="email_address" AUTOCOMPLETE="OFF"></TD>          \
        </TR>\
        <TR>\
          <TH>Living Arrangement *</TH>\
          <TD><SELECT id="living" name="living">\
            <OPTION selected value="">Please select</OPTION>\
            <OPTION value="Own">Own</OPTION>\
            <OPTION value="Buy">Buy</OPTION>\
            <OPTION value="Other (employer subsided)">Other (employer   subsided)</OPTION>\
      </SELECT></TD>\
          <TD rowspan="5"></td>\
        </TR>\
        <TR>\
          <TH>Employment Status *</TH>\
          <TD><SELECT id="emp" name="emp">\
            <OPTION selected value="">Please   select</OPTION>\
            <OPTION value="Full Time Permanent more than 3 months">Full Time   Permanent more than 3 months</OPTION>\
            <OPTION value="Part Time">Part Time</OPTION>\
            <OPTION value="Pensioner">Pensioner</OPTION>\
            <OPTION value="Unemployed">Unemployed</OPTION>\
          </SELECT></TD>          \
        </TR>\
        <TR>\
          <TH>Credit Rating *</TH>\
          <TD><SELECT id="credit" name="credit">\
            <OPTION selected value="">Please select</OPTION>\
            <OPTION value="Excellent - No Recorded Defaults">Excellent - No Recorded   Defaults</OPTION>\
            <OPTION value="Unsure">Unsure</OPTION>\
          </SELECT></TD>          \
        </TR>\
        <TR>\
          <TH>Preferred Dealership *</TH>\
          <TD><SELECT id="purchfrom" name="purchfrom">\
            <OPTION selected value="">Please select</OPTION>\
            <OPTION value="North">Northern Dealership</OPTION>\
            <OPTION value="South">Southern Dealership</OPTION>\
          </SELECT></TD>          \
        </TR>\
        <TR>\
          <TH>Purchase Price *</TH>\
          <TD><INPUT id="price" size="50" name="price"></TD>          \
        </TR>\
        <TR>\
          <TH>Deposit/Trade In *</TH>\
          <TD><INPUT id="dep" size="50" name="dep"></TD>\
                    <TD>&nbsp;</TD>\
        </TR>\
        <TR>\
          <TH>Loan Amount *</TH>\
          <TD><INPUT id="amt" size="50" name="amt"></TD>\
          <TD>&nbsp;</TD>\
        </TR>\
        <TR>\
          <TH></TH>\
          <TD><INPUT value="Submit" type="submit" name="finance"></TD>\
          <TD>&nbsp;</TD> \
        </TR>\
      </TBODY>\
    </TABLE> \
  </FORM>\
</DIV>');
    $('.fancyzoom').fancyZoom();
});

YEAR MAKE和MODEL在代码中的位置是我要插入PHP数组[make],[model]等等。可行....?

1 个答案:

答案 0 :(得分:0)

最简单的方法是通过ajax加载元素的内容。例如(在jQuery中):

$('#content_outer').load('ajax/car_data.php');

这里ajax / cardata.php的代码如下:

 <div id="fancy_zoom_large_financeapp">
 <form action="" id="finance-app-form" method="POST">
 <H2>Apply for Finance</H2>
 etc.
 <?=$year_of_car?>

或者,您可以仅针对汽车的年份/品牌/型号发送AJAX查询。