I am struggeling with a Jquery post call that returns SyntaxError unexpected token if I try to require_once the needed files to instantiate the php object and get the propertie of that object. What is weird is that it seems to be working on my remote server but not on my local testing server. Here is the code:
Part of the php file making the Jquery call:
<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>
This is the getNewCustRef() function :
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); }
});
}
And this is the getSelectData.php file that I can´t get to require the needed function file:
<?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);
?>
If I comment out the require once and set $custRefEmail = $customer_ref_id It returns the ID that got sent in by the post function. So the data gets there allright. It all fails when I try to include any file... ??? And yes I have spent hours on this googling and looked in here at all sorts of questions.... Iam depserate for help...
You should run a phpinfo(); to see that both PHP versions include JSON support and all of the other needed libraries.
Then I'd double check to make sure that the file is in the directory that is being looked at. In this case, it's the grandparent directory (../../file.php).
I'd then create a couple of files to see if I could get the include / require_once functions to work.
Sometimes working with remote/local you can easily get mixed up. Just today I was editing a local copy of a file and tearing my hair out because the remote file wasn't showing any changes!