Passing Javascript String to PHP output - Stack Overflow

I'm using this web service that prints out table using Javascript functions. I need the table to p

I'm using this web service that prints out table using Javascript functions. I need the table to print out in plain html. This could be done if the Javascript string was transferred to a PHP file. So basically, this is similar to AJAX, but it is in reverse.

I'm using this web service that prints out table using Javascript functions. I need the table to print out in plain html. This could be done if the Javascript string was transferred to a PHP file. So basically, this is similar to AJAX, but it is in reverse.

Share Improve this question asked Apr 26, 2011 at 10:55 sonics876sonics876 9572 gold badges14 silver badges31 bronze badges 1
  • Your question needs more details. Your description of what you want is too sketchy. – mario Commented Apr 26, 2011 at 10:59
Add a ment  | 

4 Answers 4

Reset to default 4

You could do that with ajax also

var value = 'This is a test';
if ($(value).val() != 0) {
$.post("jquery2php.php", {
    variable:value
}, function(data) {
    if (data != "") {
        alert('We sent Jquery string to PHP : ' + data);
    }
});
}

Important thing here is we are using $.post, so we are can gather the information with $_POST

We are sending only 1 value, named variable.

PHP part;

<?php 
$jqueryVariable = $_POST['variable'];
echo $jqueryVariable;
?>

I believe, this is the most elegant way to achieve what you want.

not necessarily reverse, You could pass the string as a URL variable (www.yoursite./?string=yourvariable) and have PHP process it from there.

I've quoted a ugly method down here But i dont remend this..

Instead store values in hidden fields in forms and access them through js or do something else..

<?php    
echo "<script type=text/javascript>var x = $value; </script>";    
?>

then use the variable x in js..

Anyway if you explain ur situation a bit clearer, we can give u best alternate solution

what you should do is use jQuery's .load() to load in the php's html results into the page

in the docs i've linked above they give this example

<script>
$("#success").load("/not-here.php", function(response, status, xhr) {
  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $("#error").html(msg + xhr.status + " " + xhr.statusText);
  }
});
  </script>

EDIT

in response to your ment on Pixeler's post. You will not be able to just view the source of a ajax based solution. if your ultimate goal is to be able to read the source you have basically three options

  1. send them to a new page
  2. load in an iframe
  3. do it the way you have, use fire fox and web devloper addon which will allow you to view generated source. (or something similar)

I'm not sure why there is a need to see the source users don't really care about the source typically the developer uses that

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744384991a4571618.html

相关推荐

  • Passing Javascript String to PHP output - Stack Overflow

    I'm using this web service that prints out table using Javascript functions. I need the table to p

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信