将PHP变量值传递给jquery函数 [英] pass PHP variable value to jquery function

查看:340
本文介绍了将PHP变量值传递给jquery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码无法正常工作.我想要的只是将变量$something发送到page.php

This code is not working properly. What i want is just send the variable $something to the page.php

正确的方法是什么? :data: <? php $something; ?>,

What is the correct way to do this ? : data: <? php $something; ?>,

脚本

$something = "text";

    $.ajax({
    url: "page.php",
    type: "post",
    dataType: "html",
    data: <? php $something; ?>, 
    success: function (data) {
        $('#total').load('xxx.php');
    }
    });

推荐答案

myFile.php:

myFile.php:

<?php $something = 'text'; ?>

<script>
$.ajax({
  url: "page.php",
  type: "post",
  dataType: "html",
  data: '<?php echo $something; ?>', 
  success: function (data) {
    $('#total').load('xxx.php');
  }
});
</script>

这篇关于将PHP变量值传递给jquery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆