duanlu9557 2013-04-16 17:47
浏览 83
已采纳

PHP数组返回null

I have a html form with a button on which there is a onclick event

    <form id = "abc" action = "xyz.php" method = "post">
      <input type="button" name="submitButton" value="Submit" 
            id="submitButton" onclick = "Function()">
     </form>

In the JS code, I am trying to post a value of a textbox and trying to get the array from the PHP through json_encode.

var valueToSend = $('#textbox').val();
var imagesReturned = new Array();
$.ajax({
        url: "xyz.php",
        type: "POST",
        data: valueToSend,
        dataType:"json",
        success: function(result) {        
            var data = jQuery.parseJSON(result);
            alert(data);
        }
    });

And here is my PHP code,

        if(isset($_POST['valueToSend'])) 
        {
            $searchValues = explode(' ',$_POST['valueToSend']);
           // Some processing here
            echo (json_encode($responseArray));

        }

When I alert the data, I get null, What am I missing?

Thanks!

  • 写回答

4条回答 默认 最新

  • drnf593779 2013-04-16 20:25
    关注

    The problem was in the PHP code.

    I removed the check, if(isset($_POST['valueToSend'])) and its working...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效