logo

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ
No Result
View All Result
logo
No Result
View All Result
Trang chủ how do i pass javascript variables to php

HOW DO I PASS JAVASCRIPT VARIABLES TO PHP

by Admin _ August 03, 2022

var1 và var2 are javascript variables on the same page. I know client side variable cannot be passed to server side. But is there any workaround as the variables are in the same page.

Bạn đang xem: How do i pass javascript variables to php


*

Trending sort Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping khổng lồ surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch khổng lồ Trending sort
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
In order for you khổng lồ make this happen - I believe - you have to use AJAX.

The code will look like this:

$.ajax( url: "your_script.php", type: "POST", data: var1: javascript_var_1, var2: javascript_var_2, success: function(data) console.log("success"); );Your PHP will look similar lớn this (without keeping in mind the JSON encode:

Then you can JSON encode the results & pretty much output đầu ra them on the success. Your php script - however - must live on another php file.

Also, escape your data. Use prepared statements.

Xem thêm: Bầu Chửa Bụng Trên Là Trai Hay Gái Phổ Biến Giúp Ba Mẹ Dự Đoán Giới Tính Con


share
Follow
answered May 2, năm trước at 19:52
*

JJPPJJPP
76922 gold badges1010 silver badges2626 bronze badges
2
showroom a phản hồi |
1
In theory, you could pass the vars lớn php via some sort of ajax call. I think it would go something like...

JavaScript:

var data = "var1": $("selector").val(), "var2": $("selector").val();$.ajax( type: "post", url: "path-to-your-file.php", data: data, timeout: 50000).done(function(response) console.log(response);).fail(function(error) // uh-oh.);php:

Otherwise, you could use:

cookie hidden input

php:

NOTE: you will want khổng lồ sanitize the data. Using raw cookie and/or input đầu vào values could lead to lớn some less than desirable results.


share
Follow
edited May 2, năm trước at 20:23
answered May 2, năm trước at 19:57
*

DamonDamon
3,65277 gold badges3838 silver badges8787 bronze badges
add a bình luận |
0
Use Method Post in AJAX or Form!! to lớn send js variable in Php & receive it in php using $_post< name_of_obj >;


giới thiệu
Follow
answered May 2, năm trước at 19:56
*

ashbuildsashbuilds
1,4011616 silver badges3232 bronze badges
địa chỉ cửa hàng a bình luận |

Your Answer


Thanks for contributing an answer khổng lồ Stack Overflow!

Please be sure to lớn answer the question. Provide details & share your research!

But avoid …

Asking for help, clarification, or responding khổng lồ 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.


Draft saved
Draft discarded

Sign up or log in


Sign up using Google
Sign up using Facebook
Sign up using email and Password
Submit

Post as a guest


Name
thư điện tử Required, but never shown


Post as a guest


Name
thư điện tử

Required, but never shown


Post Your Answer Discard

By clicking “Post Your Answer”, you agree to lớn our terms of service, privacy policy and cookie policy


Not the answer you're looking for? Browse other questions tagged javascript php mysql or ask your own question.


The Overflow Blog
Featured on Meta
Linked
2
How to lớn create a select list with javascript and populate it with php sql?
Related
1371
How can I đầu ra MySQL query results in CSV format?
1655
Is JavaScript a pass-by-reference or pass-by-value language?
1986
How bởi I check if a variable is an array in JavaScript?
2695
How can I get query string values in JavaScript?
4944
Reference — What does this symbol mean in PHP?
2467
kiểm tra if a variable is a string in JavaScript
2211
JavaScript kiểm tra if variable exists (is defined/initialized)
1468
JavaScript phối object key by variable
751
How vì chưng I pass variables và data from PHP lớn JavaScript?
Hot Network Questions more hot questions

Question feed
Subscribe to RSS
Question feed lớn subscribe to this RSS feed, copy và paste this URL into your RSS reader.


*

default
Stack Overflow
Products
Company
Stack Exchange Network
Site thiết kế / logo © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2022.8.2.42721


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device & disclose information in accordance with our Cookie Policy.

Share Tweet Linkedin Pinterest
Previous Post

Elasticsearch with php

Next Post

Array wrap php

CÙNG CHUYÊN MỤC

form register php

Form register php

09/04/2021
fantastic blog (cms) in php with source code

Fantastic blog (cms) in php with source code

28/04/2021
validate form php javascript

Validate form php javascript

28/04/2021
http diendanlequydon com viewtopic php style 6

Http diendanlequydon com viewtopic php style 6

28/04/2021
top 17 how to add values in multidimensional array php hay nhất 2022

Top 17 how to add values in multidimensional array php hay nhất 2022

14/08/2022
bài tập php của khtn

Bài tập php của khtn

14/08/2022
decode base64 with python give error

Decode base64 with python give error

14/08/2022
chia lấy nguyên trong php

Chia lấy nguyên trong php

13/08/2022

Newsletter

The most important automotive news and events of the day

We won't spam you. Pinky swear.

Chuyên Mục

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ

News Post

  • Kristallnacht là gì

About

Chúng tôi tạo ra trang web nhằm mục đích mang lại kiến thức bổ ích cho cộng đồng, các bài viết được sưu tầm từ nhiều nguồn trên internet giúp mang lại kiến thức khách quan dành cho bạn

©2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng

Liên Hệ - Giới Thiệu - Nội Quy - Bảo Mật

No Result
View All Result
  • Trang chủ
  • Chuyên mục
    • Hỏi Đáp
    • Kiến Thức
    • Sức Khỏe
    • Tử Vi
    • Công Nghệ
  • Lưu trữ
  • Liên hệ

© 2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng.