Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need to understand how the logic of Ruby (ROR) works for web development. I've already tried tutorials of Ruby, but need to see a code of simple web system.
Could you please rewrite the following simple code with PHP, as it's written on ROR? You would help me a lot.
// HTML/CSS/JS:
<html>
<head>..
<script>
function send(){
var xmlhttp = getXmlHttp();
xmlhttp.open('POST', '/send.php', true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("data=" + $("#test").val() );
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4)
if(xmlhttp.status == 200)
if(xmlhttp.responseText) alert("Done");
}
</script>
</head>
<body>
<input type='text' id='test' />
<button onclick='send()'>OK</button>
</body>
</html>
// Send.php
<?php>
$data=$_POST['data'];
if($data=='1')
echo true;
else
echo false;
</php>
First of please try this guide to see how Ruby on Rails (!= ruby!!) works.
In your case this code would make sense:
# config/routes.rb
Rails.application.routes.draw do
post 'example' => 'example#something'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Your controller:
# app/controllers/example_controller.rb
class ExampleController < ApplicationController
def something
result = { ok: params[:data] == "1" }
render json: result
end
end
So you could post to /example and get a json object with: {"ok": <true/false>}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need some help with this PHP pages.
I don't understand
session_start();
require("config/db.php");
if(isset($_GET['page'])){
$pages=array("menu","cart");
if(in_array($_GET['page'], $pages)) {
$_page=$_GET['page'];
}else{
$_page="menu";
}
}else{
$_page="menu";
}
?>
My code at the bottom calls $_page and it will display that PHP page,
in this case, menu.php. How do I make it call menu2.php if I were to select an option that changes the value to menu2?
EDIT:
Thanks for all your comments! I would like to add on that this is just a container in the website, and my output will be derived from
Please look at the sample code i created below, this should give you an idea, I hope.
<section href="#" id="showItem"></section>
<select id="options">
<option value="page1.php">Page 1</option>
<option value="page2.php">Page 2</option>
</select>
<script type="text/javascript" src="js/jquery-2.2.0.min.js"></script>
<script type="text/javascript">
var options = $('select#options').val();
var section = $('section#showItem');
var getPage = function (url) {
$.get(url).success(function (data) {
section.html(data);
}).error(function () {
section.html("error loading page");
});
};
$('select#options').change(function () {
var options = $('select#options').val();
getPage(options);
});
$(document).ready(function () {
getPage(options);
});
</script>
Use
header("Location:" . $_page . ".php");
where location can be any valid url/page name on the server relative to the current document.
just try: header('Location:'.$_page.'.php'); it will redirect to selected page
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make a game in HTML and PHP and I'm pretty new to coding. The point is I need to execute a PHP script by clicking an HTML element. Is this possible?
My code would look something like this
$money = 100;
and by clicking on:
<a>rob a shop</a>
it must excecute:
function rob_shop(){
$money += 75;
echo "You now have $money $";}
Try this, is PHP:
<?php
if (isset($_GET['money'])) {
$money = rob_shop($_GET['money']);
echo 'You now have: '.$money.'<br>';
} else {
$money = 100;
echo 'You now have: '.$money.'<br>';
}
echo 'rob a shop';
function rob_shop($money){
$money = $money + 75;
return $money;
}
?>
But the best way to do it is with ajax to avoid refreshing the page.
Add extra param to link and check with php and call function.
rob money
Then check for link
if (isset($_GET['fun']))
{
runFun();
}
you will need to use javascript and an ajax call or you could just do it in javascript.
<a id="shop">rob a shop</a>
<div id="response"></div>
// include jquery
<script>
$( "#shop" ).click(function() {
var money = money + 75;
$("#response").html( "YOU NOW HAVE $"+money );
// or make an ajax call to a php script and return the value
});
</script>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My question is very very similar to this one
How to get jQuery variable value in PHP file
The difference is I have some code samples. I just cant seem to get a satisfactory answer for what I am looking for. I am doing all these in one php file. Is this even possible?
I want to store categoryChoiceVal into $category
Here is the html
<select class="categoryChoice ">
<option>Gym class</option>
<option>Math tutorial</option>
<option>Basketball court</option>
</select>
the php
<?php
$category = '';
$query_string = "https//this_is_a_dummy_string.htm?{$category}";
$data = file_get_contents($query_string);
?>
I am catching the selection from the select tag by doing this
$(function(){
$('select').change(function() {
var categoryChoiceVal = $('.categoryChoice option:selected').text();
});
});
Thanks in advance
<?php
$category = '';
if (isset($_POST['categoryChoiceVal'])){
$category = $_POST['categoryChoiceVal'];
}
$query_string = "https//this_is_a_dummy_string.htm?{$category}";
$data = file_get_contents($query_string);
?>
$(function(){
$('select').change(function() {
$.post('phpUrl',{
categoryChoiceVal:$('.categoryChoice option:selected').text()
});
});
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am attempting to return a value from a php class from within Javascript:
<html>
<?php
function tester()
{
return "testing";
}
?>
<script type="text/javascript">
var val= "<?php tester(); ?>";
document.write(val);
document.write('Finished!');
</script>
</html>
Nothing is being returned, rather I simply get a blank screen (apart from the "Finished" message) =(
That is happening because you are just returning the value, to output you have to echo it:
<?php echo tester(); ?>
You're not doing anything with the output of tester(). Try this instead:
var val= <?php echo json_encode(tester()); ?>;
You need to echo it.
Either use:
var val= "<?php echo tester(); ?>"
Or if you have short tags enabled:
var val= "<?=tester()?>"
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using placeholder attribute provided in html 5 to get placeholder effect.
<input id="search" class="hasPlaceholder" type="text" placeholder="Personal Trainer"
value="" name="search">
also I have added code to clear the placeolder on submit.
$(function() {
if(!$.support.placeholder) {
var active = document.activeElement;
$(':text').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder'));
$(this).addClass('hasPlaceholder');
}
});
$(':text').blur();
$(active).focus();
$('form').submit(function () {
$(this).find('.hasPlaceholder').each(function() {
var input = $(this);
input.removeClass('hasPlaceholder');
if (input.val() == input.attr('placeholder')) {
input.removeAttr('placeholder');
input.val("");
}
});
});
}
});
but still it gives placeholder value after submit.
When I entered the last part of your question (Please suggest where i can get list of all Occupation/Industry in excel format) into google, I came across this link on page 1. It has a link to this spreadsheet which contains the exact thing you are looking for. I like helping folks, but seriously, do a little research and googling first.
11-0000 Management Occupations
11-1000 Top Executives
11-1010 Chief Executives
11-1011 Chief Executives
11-1020 General and Operations Managers
11-1021 General and Operations Managers
11-1030 Legislators
11-1031 Legislators
Example Data.