使用jquery ajax将php变量发送到php文件?

时间:2022-09-15 09:26:47

i want to send a php variable $thread_id to php file using jquery ajax, so the php file can get all posts for $thread_id and echo it back to main file.

我想使用jquery ajax将php变量$ thread_id发送到php文件,因此php文件可以获取$ thread_id的所有帖子并将其回送回主文件。

it doesnt work when i type:

当我输入时它不起作用:

$.get("ajaxcall_reply.php", thread_id: $thread_id, function(data) {
     $("#threads").html(data);
});

how should i type?

我该怎么打字?

3 个解决方案

#1


0  

Do you know what $thread_id is outputting? Try putting it into a variable of its own and looking at the output before putting it in the get function. It might have symbols or things that are messing up your javascript syntax. Do you have an example output? Additionally the get method returns the XMLHttpRequest object (data) so you might want to look into setting the type of data to be returned to callback function: "xml", "html", "script", "json", "jsonp", or "text".

你知道$ thread_id输出的是什么吗?尝试将其放入自己的变量中并在将其放入get函数之前查看输出。它可能有符号或东西搞乱你的JavaScript语法。你有一个例子输出吗?此外,get方法返回XMLHttpRequest对象(数据),因此您可能需要查看设置要返回到回调函数的数据类型:“xml”,“html”,“script”,“json”,“jsonp”,或“文字”。

#2


0  

Try this:

尝试这个:

$.get("ajaxcall_reply.php", {thread_id: $thread_id}, function(data) { $("#threads").html(data); });

#3


0  

  <script>
  $.get(url, { get_var: '<?php echo $phpvar ?>' }, function(data) { alert(data); });
  </script>

at the URL:

在URL:

  <?php
  echo $_GET['get_var'];
  ?>

#1


0  

Do you know what $thread_id is outputting? Try putting it into a variable of its own and looking at the output before putting it in the get function. It might have symbols or things that are messing up your javascript syntax. Do you have an example output? Additionally the get method returns the XMLHttpRequest object (data) so you might want to look into setting the type of data to be returned to callback function: "xml", "html", "script", "json", "jsonp", or "text".

你知道$ thread_id输出的是什么吗?尝试将其放入自己的变量中并在将其放入get函数之前查看输出。它可能有符号或东西搞乱你的JavaScript语法。你有一个例子输出吗?此外,get方法返回XMLHttpRequest对象(数据),因此您可能需要查看设置要返回到回调函数的数据类型:“xml”,“html”,“script”,“json”,“jsonp”,或“文字”。

#2


0  

Try this:

尝试这个:

$.get("ajaxcall_reply.php", {thread_id: $thread_id}, function(data) { $("#threads").html(data); });

#3


0  

  <script>
  $.get(url, { get_var: '<?php echo $phpvar ?>' }, function(data) { alert(data); });
  </script>

at the URL:

在URL:

  <?php
  echo $_GET['get_var'];
  ?>