Echo not working in JQuery Ajax call [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Below is a code snippet of my PHP file - I am trying to call a PHP function on click of a button. Simple echo is not working - appreciate any help
/* This function saves Add or Make of Model to Database
*/
$('#addmake-btn').live('click',function(){
<?php
echo "Not Working";
?>
});
</script>

first you need to know about how client side and server side language works.
server side languages like PHP will execute in server, you cant execute them in client side unlike javascript or some other client side language.

$('#addmake-btn').live('click',function(){
var printVal = "<?php echo "Not Working"; ?>";
document.write(printVal);
});

Related

GPS Location Coordinaties in PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I write a code that gets the current location coordinates (LLA) in my web browser using PHP .
Is it possible by using GPS via HTTP or something like that ?
please help
Thanks
You will need to use the brower's geolocation API, for example as shown here.
Then, you simply pass the parameters to a PHP script using whatever method you like, a form, or a jQuery post.

Get window size with php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the problem this code:
$window_width= '<script>screen.availWidth</script>';
$window_height= '<script>screen.availHeight</script>';
any idea?
Nothing wrong in your code, but you can't get any values in PHP variable, because PHP is Server side scripting language.
You need JavaScript, not PHP.
var screenWidth = window.screen.width,
var screenHeight = window.screen.height;
You can then send it to the server via Ajax (with an XmlHttpRequest).
You seem to be misunderstanding the basic concepts of how PHP and HTML/JavaScript works together. PHP is a server-side language and JavaScript is a client-side language.
PHP generates the output first and then it's transferred to the client where it's being executed. You're trying to do it the other way around.
What you need to do is first, generate a page using PHP, have it sent to the client for client-side execution, and from there have JavaScript perform a call that sends the information back to PHP using a GET/POST request.

How to get jQuery variable value in PHP file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I need to jQuery variable value in PHP code in same file with out calling ajax? Please help me it is possible or not. Here jQuery and PHP code here given below.
well you can make use of jquery.session plugin to store Session variable and then you can access that variable using php code.
Sample Code
$(function() {
$.session("myVar", "value");
});
In PHP
echo $_SESSION['myVar'];

onclick="USER._like('161', this);" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I've seen sites where instead of form buttons, they use links like that
onclick="USER._like('161', this);"
And when I click on it, it dynamically inserts the data into the database.
What is this called? And are there any tutorials around here?
Thanks.
That is a javascript event handler. Presumablly the function USER.like ( or to be exact the method like on the object USER) makes an ajax call and sends the value 161 to the server which is then somehow recorded.
That said its much better to do it in an unobtrusive manner, meaning that you would not write function call into an html attribute but rather attach an even handler pragmatically from javascript... using assuming this html:
<a class="like-button" href="#" data-id="161">Like</a>
Achieving the same thing in an unobtrusive manner with jquery would look like:
$(function (){
$('.like-button').on('click', function (e) {
e.preventDefault();
USER.like($(this).attr('data-id'), this);
});
});

how do i force a user to go back twice on a mobile web page using php or javascript without the user clicking any link or button [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
how do I force a user to go back twice on a mobile web page using PHP or jAVASCRIPT without the user clicking any link or button.
something like using history.back() without a user having to click on anything
In javascript
function goBackTwice()
{
window.history.go(-2)
}
You may want to look into https://github.com/browserstate/history.js/ for a more robust client side solution.

Categories