Trying to use AJAX to grab parameter of function and pass to PHP codeHow do you pass a function as a parameter in C?Is there a better way to do optional function parameters in JavaScript?startsWith() and endsWith() functions in PHPSet a default parameter value for a JavaScript functionHow can I pass a parameter to a setTimeout() callback?Passing an array as a function parameter in JavaScriptjQuery Ajax POST example with PHPWhy shouldn't I use mysql_* functions in PHP?Pass a JavaScript function as parameterHow do I pass variables and data from PHP to JavaScript?
If every star in the universe except the Sun were destroyed, would we die?
Schrodinger's Cat Isn't Meant To Be Taken Seriously, Right?
The Green Glass Door, Revisited
What makes things real?
Can you pop microwave popcorn on a stove?
Furthest distance half the diameter?
Capacitors with same voltage, same capacitance, same temp, different diameter?
Why does 8 bit truecolor use only 2 bits for blue?
What makes an ending "happy"?
What's the biggest difference between these two photos?
Bit floating sequence
How to run NPCs with complicated mechanics?
Why can't some airports handle heavy aircraft while others do it easily (same runway length)?
How invisible hand adjusts stock prices if company is listed on multiple exchanges, under multiple currencies, and one of the currencies plunges?
What explains the Genie's fate?
When did computers stop checking memory on boot?
Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?
Problem with listing a directory to grep
Did "Dirty Harry" feel lucky?
What precisely does the commonly reported network hash rate refer to?
How do English-speaking kids loudly request something?
Bacteria vats to generate edible biomass, require intermediary species?
Poor management handling of recent sickness and how to approach my return?
Are fast interviews red flags?
Trying to use AJAX to grab parameter of function and pass to PHP code
How do you pass a function as a parameter in C?Is there a better way to do optional function parameters in JavaScript?startsWith() and endsWith() functions in PHPSet a default parameter value for a JavaScript functionHow can I pass a parameter to a setTimeout() callback?Passing an array as a function parameter in JavaScriptjQuery Ajax POST example with PHPWhy shouldn't I use mysql_* functions in PHP?Pass a JavaScript function as parameterHow do I pass variables and data from PHP to JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an HTML input with a function and parmeter set to it like so
<input onclick='myFunc($count)' type='button' value='ClickMe'>;
I also have script references to JQuery and my script file
<script src="jquery.js"></script>
<script src="myscript.js"></script>
Inside my myscript.js file I have the contents as such
function myFunc(x)
alert(x);
$(document).ready(function()
$.ajax(
url: "myphp.php",
method: "post",
data: param1: "x" ,
dataType: "text",
success: function(strMessage)
)
)
Here is my myphp.php file
<?php
$param1 = $_GET['param1'];
echo $param1;
?>
As you can see in the javascript file, I have alert(x); to test that the function is grabbing the $count variable and so far that is working (the correct value appears in the alert box). However, I want to pass that x parameter to the PHP script but my PHP script won't echo anything, I assume the line where I have param1 is wrong. Any tips?
javascript php jquery ajax function
add a comment |
I have an HTML input with a function and parmeter set to it like so
<input onclick='myFunc($count)' type='button' value='ClickMe'>;
I also have script references to JQuery and my script file
<script src="jquery.js"></script>
<script src="myscript.js"></script>
Inside my myscript.js file I have the contents as such
function myFunc(x)
alert(x);
$(document).ready(function()
$.ajax(
url: "myphp.php",
method: "post",
data: param1: "x" ,
dataType: "text",
success: function(strMessage)
)
)
Here is my myphp.php file
<?php
$param1 = $_GET['param1'];
echo $param1;
?>
As you can see in the javascript file, I have alert(x); to test that the function is grabbing the $count variable and so far that is working (the correct value appears in the alert box). However, I want to pass that x parameter to the PHP script but my PHP script won't echo anything, I assume the line where I have param1 is wrong. Any tips?
javascript php jquery ajax function
remove the quotes from data: param1: "x" , in your javascript and addalert(strMessage);
inside of thesuccess: function( strMessage )
curly braces.
– JasonB
Mar 28 at 7:03
I followed your instructions and removed the alert(x); function underr myFunc() and when I click the button I get an alert but nothing inside the alert. This would mean that either the parameter is not being passed in AJAX and/or PHP? It is kind of hard to test if AJAX is calling the PHP file from within the web browser.
– whatitiswhatsup
Mar 28 at 7:08
add a comment |
I have an HTML input with a function and parmeter set to it like so
<input onclick='myFunc($count)' type='button' value='ClickMe'>;
I also have script references to JQuery and my script file
<script src="jquery.js"></script>
<script src="myscript.js"></script>
Inside my myscript.js file I have the contents as such
function myFunc(x)
alert(x);
$(document).ready(function()
$.ajax(
url: "myphp.php",
method: "post",
data: param1: "x" ,
dataType: "text",
success: function(strMessage)
)
)
Here is my myphp.php file
<?php
$param1 = $_GET['param1'];
echo $param1;
?>
As you can see in the javascript file, I have alert(x); to test that the function is grabbing the $count variable and so far that is working (the correct value appears in the alert box). However, I want to pass that x parameter to the PHP script but my PHP script won't echo anything, I assume the line where I have param1 is wrong. Any tips?
javascript php jquery ajax function
I have an HTML input with a function and parmeter set to it like so
<input onclick='myFunc($count)' type='button' value='ClickMe'>;
I also have script references to JQuery and my script file
<script src="jquery.js"></script>
<script src="myscript.js"></script>
Inside my myscript.js file I have the contents as such
function myFunc(x)
alert(x);
$(document).ready(function()
$.ajax(
url: "myphp.php",
method: "post",
data: param1: "x" ,
dataType: "text",
success: function(strMessage)
)
)
Here is my myphp.php file
<?php
$param1 = $_GET['param1'];
echo $param1;
?>
As you can see in the javascript file, I have alert(x); to test that the function is grabbing the $count variable and so far that is working (the correct value appears in the alert box). However, I want to pass that x parameter to the PHP script but my PHP script won't echo anything, I assume the line where I have param1 is wrong. Any tips?
javascript php jquery ajax function
javascript php jquery ajax function
asked Mar 28 at 6:59
whatitiswhatsupwhatitiswhatsup
12 bronze badges
12 bronze badges
remove the quotes from data: param1: "x" , in your javascript and addalert(strMessage);
inside of thesuccess: function( strMessage )
curly braces.
– JasonB
Mar 28 at 7:03
I followed your instructions and removed the alert(x); function underr myFunc() and when I click the button I get an alert but nothing inside the alert. This would mean that either the parameter is not being passed in AJAX and/or PHP? It is kind of hard to test if AJAX is calling the PHP file from within the web browser.
– whatitiswhatsup
Mar 28 at 7:08
add a comment |
remove the quotes from data: param1: "x" , in your javascript and addalert(strMessage);
inside of thesuccess: function( strMessage )
curly braces.
– JasonB
Mar 28 at 7:03
I followed your instructions and removed the alert(x); function underr myFunc() and when I click the button I get an alert but nothing inside the alert. This would mean that either the parameter is not being passed in AJAX and/or PHP? It is kind of hard to test if AJAX is calling the PHP file from within the web browser.
– whatitiswhatsup
Mar 28 at 7:08
remove the quotes from data: param1: "x" , in your javascript and add
alert(strMessage);
inside of the success: function( strMessage )
curly braces.– JasonB
Mar 28 at 7:03
remove the quotes from data: param1: "x" , in your javascript and add
alert(strMessage);
inside of the success: function( strMessage )
curly braces.– JasonB
Mar 28 at 7:03
I followed your instructions and removed the alert(x); function underr myFunc() and when I click the button I get an alert but nothing inside the alert. This would mean that either the parameter is not being passed in AJAX and/or PHP? It is kind of hard to test if AJAX is calling the PHP file from within the web browser.
– whatitiswhatsup
Mar 28 at 7:08
I followed your instructions and removed the alert(x); function underr myFunc() and when I click the button I get an alert but nothing inside the alert. This would mean that either the parameter is not being passed in AJAX and/or PHP? It is kind of hard to test if AJAX is calling the PHP file from within the web browser.
– whatitiswhatsup
Mar 28 at 7:08
add a comment |
3 Answers
3
active
oldest
votes
In your AJAX call you are using a POST method, so in order to catch the variable in PHP you need to access it from $_POST:
<?php
$param1 = $_POST['param1'];
echo $param1;
?>
add a comment |
You're making the XHR with POST method
method: "post",
and youre looking for it in the GET array
$_GET['param1']
;
Change either to post or get (keeping in mind your scenario) and you should be good imo.
read more here to know about the different methods of sending http requests: https://www.guru99.com/php-forms-handling.html
add a comment |
You are using post method in AJAX but trying to grab the value in $_GET
which is wrong.
In your PHP code, just replace $_GET['param1']
with $_POST['param1']
and it works.
or If you like to use $_GET
in your PHP code then change the method in AJAX or use $.get
. Examples can be found on W3School.
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391794%2ftrying-to-use-ajax-to-grab-parameter-of-function-and-pass-to-php-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your AJAX call you are using a POST method, so in order to catch the variable in PHP you need to access it from $_POST:
<?php
$param1 = $_POST['param1'];
echo $param1;
?>
add a comment |
In your AJAX call you are using a POST method, so in order to catch the variable in PHP you need to access it from $_POST:
<?php
$param1 = $_POST['param1'];
echo $param1;
?>
add a comment |
In your AJAX call you are using a POST method, so in order to catch the variable in PHP you need to access it from $_POST:
<?php
$param1 = $_POST['param1'];
echo $param1;
?>
In your AJAX call you are using a POST method, so in order to catch the variable in PHP you need to access it from $_POST:
<?php
$param1 = $_POST['param1'];
echo $param1;
?>
answered Mar 28 at 7:05
Diego RosalesDiego Rosales
7395 silver badges16 bronze badges
7395 silver badges16 bronze badges
add a comment |
add a comment |
You're making the XHR with POST method
method: "post",
and youre looking for it in the GET array
$_GET['param1']
;
Change either to post or get (keeping in mind your scenario) and you should be good imo.
read more here to know about the different methods of sending http requests: https://www.guru99.com/php-forms-handling.html
add a comment |
You're making the XHR with POST method
method: "post",
and youre looking for it in the GET array
$_GET['param1']
;
Change either to post or get (keeping in mind your scenario) and you should be good imo.
read more here to know about the different methods of sending http requests: https://www.guru99.com/php-forms-handling.html
add a comment |
You're making the XHR with POST method
method: "post",
and youre looking for it in the GET array
$_GET['param1']
;
Change either to post or get (keeping in mind your scenario) and you should be good imo.
read more here to know about the different methods of sending http requests: https://www.guru99.com/php-forms-handling.html
You're making the XHR with POST method
method: "post",
and youre looking for it in the GET array
$_GET['param1']
;
Change either to post or get (keeping in mind your scenario) and you should be good imo.
read more here to know about the different methods of sending http requests: https://www.guru99.com/php-forms-handling.html
answered Mar 28 at 7:08
HishaamHishaam
214 bronze badges
214 bronze badges
add a comment |
add a comment |
You are using post method in AJAX but trying to grab the value in $_GET
which is wrong.
In your PHP code, just replace $_GET['param1']
with $_POST['param1']
and it works.
or If you like to use $_GET
in your PHP code then change the method in AJAX or use $.get
. Examples can be found on W3School.
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
add a comment |
You are using post method in AJAX but trying to grab the value in $_GET
which is wrong.
In your PHP code, just replace $_GET['param1']
with $_POST['param1']
and it works.
or If you like to use $_GET
in your PHP code then change the method in AJAX or use $.get
. Examples can be found on W3School.
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
add a comment |
You are using post method in AJAX but trying to grab the value in $_GET
which is wrong.
In your PHP code, just replace $_GET['param1']
with $_POST['param1']
and it works.
or If you like to use $_GET
in your PHP code then change the method in AJAX or use $.get
. Examples can be found on W3School.
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
You are using post method in AJAX but trying to grab the value in $_GET
which is wrong.
In your PHP code, just replace $_GET['param1']
with $_POST['param1']
and it works.
or If you like to use $_GET
in your PHP code then change the method in AJAX or use $.get
. Examples can be found on W3School.
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
answered Mar 28 at 7:11
Sami Ahmed SiddiquiSami Ahmed Siddiqui
1,8651 gold badge9 silver badges20 bronze badges
1,8651 gold badge9 silver badges20 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391794%2ftrying-to-use-ajax-to-grab-parameter-of-function-and-pass-to-php-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
remove the quotes from data: param1: "x" , in your javascript and add
alert(strMessage);
inside of thesuccess: function( strMessage )
curly braces.– JasonB
Mar 28 at 7:03
I followed your instructions and removed the alert(x); function underr myFunc() and when I click the button I get an alert but nothing inside the alert. This would mean that either the parameter is not being passed in AJAX and/or PHP? It is kind of hard to test if AJAX is calling the PHP file from within the web browser.
– whatitiswhatsup
Mar 28 at 7:08