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条)

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd