Sunday, June 3, 2018

Why can I use PHP in some of my Javascript but not in specific places?


I am fundamentally confused about something in my code.



If I code this on one of my .php pages:


$userEmail = $_SESSION["inputEmail"];

and then use it in an AJAX call inside one of my Javascript functions:


function firstFunction() {
$.ajax({
url: someUrl.php?inputEmail='
sync: true,
success: function(result) {
$("#someDiv").html(result)
}
})
}

I end up getting the result I need. I am confused, however, because if in this function, I did something like this:


function secondFunction() {
if ( == "test@test.com") {
//do some stuff
}
}

It does not work. I have read answers to this exact scenario right above, but I don't understand why the first line of code I provided in this example works but this second one does not.


Initially, I expected the Javascript to be able to read $userEmail in the function above, but after viewing the page source, I see it is evaluation nothing. It looks like:


if(  == "test@test.com)

Like I said, I've looked this part up. But now I'm even more confused. Why can I do the AJAX call under firstFunction() but not secondFunction()

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...