使用jQuery从文本框传递值到PHP不起作用,请帮助 [英] passing a value to php from textbox using jquery doesnt work please help

查看:83
本文介绍了使用jQuery从文本框传递值到PHP不起作用,请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5b1.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>  

<input type="text" id="textbox">
<button id="inlinesubmit_button" type="button">submit</submit>


<script>

function call_this()
{
alert(<?php echo $_POST['text'];?>);
}


$('#inlinesubmit_button').click(function(){
    $.ajax({
        type: "POST",
        url: "sync_loading1.php",
       data: {text:$('#textbox').val()}
    });

call_this();
});

</script>

这会在警报框中显示未定义的内容,请帮助我指出我在做什么错

this gives undefined in alert box please help me in pointing out what am I doing wrong

推荐答案

您可能需要将其包装在引号('")中,以使其成为字符串.

You probably need to wrap it in quotes (' or "), to make it a string.

alert('<?php echo $_POST['text'];?>');

您似乎还忽略了JavaScript(客户端)和PHP(服务器端)的运行方式.他们无法直接沟通; PHP可以回显JavaScript,JavaScript可以对PHP文件发出HTTP请求.

It also appears you are overlooking something with how JavaScript runs (client side) and PHP (server side). They can't directly communicate; PHP can echo JavaScript, and JavaScript can make HTTP requests to PHP files.

这篇关于使用jQuery从文本框传递值到PHP不起作用,请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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