简体   繁体   English

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

[英]Echoing PHP Array into Javascript File/FancyZoom Popup

Clicking on the “Apply for Finance” button on our Vehicle Details page opens up a FancyZoom window on our website, with financeapp.js the file that is shown in the window. 单击“车辆详细信息”页面上的“申请财务”按钮,将在我们的网站上打开一个FancyZoom窗口,该窗口中显示的文件为financeapp.js。 I need to pass some variables (Year, Make and Model of Car) to this page so that they are displayed in the Finance App window that pops up over the Vehicle Details page. 我需要将一些变量(年份,品牌和汽车型号)传递到此页面,以便它们显示在“车辆详细信息”页面上方弹出的Finance App窗口中。

The Car Detail page has code like: “汽车详细信息”页面上的代码如下:

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

To show the Vehicle Make on the page, and on the FancyZoom window, I also want to have the vehicle make echoed. 为了在页面上和FancyZoom窗口上显示“车辆制造商”,我还想让车辆制造商回声。 Is this possible with Javascript? Javascript可以实现吗? Can it be so that when the Javascript window is opened, it gets the vehicle info from detail page? 打开Javascript窗口时,可以从详细信息页面获取车辆信息吗?

Putting in PHP Code into the .js file is resulting in Syntax errors. 将PHP代码放入.js文件会导致语法错误。

This is the code for financeapp.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();
});

Where YEAR MAKE and MODEL are in the code is where I want to insert to PHP Array [make], [model] etc. Doable....? 代码中YEAR MAKE和MODEL的位置是我想插入PHP Array [make],[model]等的位置。

The simplest way to do this would be to load the contents of the element via ajax. 最简单的方法是通过ajax加载元素的内容。 For example (in jQuery): 例如(在jQuery中):

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

Here ajax/cardata.php would have code like: 在这里,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?>

Alternatively, you could send an AJAX query for just the year/make/model of the car. 另外,您也可以仅针对汽车的年份/品牌/型号发送AJAX查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM