如何从jQuery的.load PHP respone [英] how get php respone from jquery .load

查看:91
本文介绍了如何从jQuery的.load PHP respone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再举一个$ C $ S为例 这是我的some3.php code:(第一档)

i give another codes for example this is my some3.php code:(First file) :

<head>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('p').click(function(){
        var who = $('input#who').val();
        var why = $('input#why').val();     
        $('#geting').load('file2.php',{who:who,why:why},function(applyData){
  if ( applyData == 'YEY . Ye have hi' ){
alert('OKKK data is ok ');
  } else{
      alert('Nooo We dont have requested output');
  }
        });
    });
});

</script>
</head>
<body>
<p> click </p>
<input type="text" id="who">
<br>
<input type="text" id="why">
<div id="geting" align="center">
</div>
</body>

我这是我的file2.php:

i this my file2.php:

<?php
echo "1";
echo "2";
    if($_REQUEST['who'] == "hi"){


    $myVariable = "YEY . Ye have hi";
    echo $myVariable;
    } else{
   $myVariable = "The out put is not Hi";
    echo $myVariable;
    }
?>

其无法正常工作,为什么? becuse我们回声1和回声2 我想jQuery的只是检查$ myVariable的数据未全的PHP回调!我想我必须使用JSON,但我不知道如何

its not work why? becuse we have echo "1" and echo "2" i want jquery just check $myVariable data not whole php callback ! i think i must use json but i dont know how

推荐答案

好了,假设你想读的使用jQuery的价值关闭您要发布帖子的页面,你可以这样做,因为你是echo'ing值在该页面通过执行以下操作:回声$ myVariable的; 现在,这是我通常如何读取值了另一个页面使用jQuery这是使用jQuery的的get()方法。

Well, assuming that you want to read the value with JQuery off the page you are posting to, you could do this, since you are echo'ing the value out in that page by doing the following: echo $myVariable; Now this is how I generally read a value off another page with JQuery which is by using JQuery's get() method.

$.get("thepagetoretrievefrom.php", function(retrievedvalue) {
    alert("Here's the data you requested: " + retrievedvalue);
    if (retrievedvalue == 1)  {
        //print out something here
        alert("The retrieved value was 1.");
    }
});

和应该检索PHP页面的价值。 thepagetoretrievefrom.php是要检索信息的页面。功能(retrievedvalue)只是表明,无论输出你是从通过JQuery的页面请求将投入retrievedvalue。然后,使用JQuery,你可以决定是否要办一个新的呼叫到另一个页面取决于什么是retrievedvalue了。 然而这是不是最好的方法来实现这一目标,因为这将打印任何可能会在该网页,但如果你是从该页面请求一个特定的值,那么它不应该是一个问题。

And that should retrieve the value from the PHP page. "thepagetoretrievefrom.php" is the page where you want to retrieve the information from. function(retrievedvalue) just indicates that whatever output you're requesting from the page via JQuery will be put into retrievedvalue. Then, using JQuery, you may decide whether you want to do a new call to another page depending on what the "retrievedvalue" was. This, however is not the best method to achieve this, since this will print whatever may be in that page, but if you are requesting one specific value from that page, then it shouldn't be an issue.

这篇关于如何从jQuery的.load PHP respone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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