PHPオブジェクトをインスタンス化し、そのオブジェクトのプロパティを取得するために必要なファイルをrequire_onceしようとすると、SyntaxError予期しないトークンを返すJqueryポストコールに苦労しています。奇妙なのは、リモート サーバーでは動作しているように見えるが、ローカル テスト サーバーでは動作していないように見えることです。コードは次のとおりです。
Jquery 呼び出しを行う php ファイルの一部:
<script type="text/javascript"> getSelectData() </script>
<!-- Dynamiclygenerate the emailadress for the first referens in the list -->
<div id="customer_ref_id">
<label for="customer_name">Kund:</label>
<p><?php echo $customer->customer_name; ?> </p>
<a href="#" class="toprghtimg"> <img src="../images/back.png"/></a>
<p class="instruction">
Välj Kundreferens i listan nedanför.
Finns ej din referens så skapa en ny referens knuten till
kunden genom att klicka på knappen nere till höger.
</p>
<div class="clearLeft"></div>
<label for="customer_ref_id">Kundreferens:</label>
<select name="customer_ref_id" id="customer_ref_id">
<?php
foreach ($customerRefs as $customerRef) { ?>
<option value="<?php echo $customerRef->id; ?>">
<?php echo $customerRef->full_name(); ?>
</option>
<?php } ?>
</select>
<input type="button" value="Skapa ny Kundreferens" onclick="getNewCustRef()" />
<div class="clearLeft"></div>
<div id="customerRefInfo"> <label>E-post:</label><p>-Ej registrerad-</p></div>
<input type="button" class="after_p" value="Ändra referensens data" onclick="changeRefData()" />
</div>
これは getNewCustRef() 関数です:
function getSelectData() {
var formData = $("#customer_ref_id select").serialize();
$.ajax({
url : 'getSelectData.php',
type : 'POST',
dataType: 'json',
data : formData,
success: function( data ) {
$('#customerRefInfo p').replaceWith('<p>'+data+'</p>' ) ;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown); }
});
}
これは、必要な関数ファイルを要求することができない getSelectData.php ファイルです。
<?php require_once("../../includes/initialize.php");
$customer_ref_id = $_POST['customer_ref_id']; // Selected customer_ref_id
$custRef = CustomerRef::find_by_id($customer_ref_id);
$custRefEmail = $custRef->e_post;
echo json_encode($custRefEmail);
?>
require を一度コメントアウトして $custRefEmail = $customer_ref_id を設定すると、ポスト関数によって送信された ID が返されます。したがって、データは問題なくそこに到達します。ファイルをインクルードしようとすると、すべて失敗します... ??? そして、はい、私はこのグーグルに何時間も費やし、あらゆる種類の質問をここで調べました....私は助けが切望されています...