jQuery script inside php not working

I have a script within some php, its inline and although we may have an issue elsewhere when I try and set an alert inside the document ready function it does work, but if I put the alert outside it but inside the script tag it works.

I’m testing as I need to try and find the what the issue is, but wanted to know if the script is running.

}
mail($to, $subject, $content, $headers);
mail($youremail, $subject, $content, $headers);
?>
<script>
$(document).ready(function(){
alert ("house");
$.ajax(
{
crossDomain: true,
contentType: "application/json; charset=utf-8",
url: "https://www.mysite.com/WebService.asmx/TC_LogRequestActivity",
data: {id: "12345", property_ID: '<?php echo $propertyId; ?>', user_ID: '<?php echo $_SESSION["user"]; ?>', intent: '<?php echo $purposeAndResponse; ?>' },
dataType: "jsonp",
success: window.location.href = "result.php?e=success",
});
});
</script>
<?php
die();
}}
?>

Have made sure I’m linked up and I am

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

Seems to throw up an alert box for me whether I put it where you have it, or bump it up a line to before the $(document).ready() line. Presume this is what you meant.

Ye it only works for me If I set the alert outside document ready, but if I put it inside I dont get it, so this I’m wondering is my problem why the function isnt running.

So in effect the document ready function isnt working, would that make sense.

have checked all the php, so there no fatal errors, and all working fine there

Ok just looked in console, and saw this

Blocked loading mixed active content “http://code.jquery.com/jquery-latest.min.js”[Learn More] enquiry.php
ReferenceError: $ is not defined[Learn More]  enquiry.php:9:1
SyntaxError: unterminated string literal[Learn More]

Its working on other pages though, so this must be the issue Im guessing

Got it, I solved that issue by changing http to https in the follwoing line

<script src="https://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.