无法从jquery访问数组

编程入门 行业动态 更新时间:2024-10-26 22:21:21
本文介绍了无法从jquery访问数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好的,在我之前的问题之前,我已经对我的代码进行了一些修改,但不知怎的,我仍然落后。

Okay prior to my previous question I have tried a bit of modification to my code but somehow I am still lagging.

这是我创建的jquery

This is jquery I have created

$(document).ready(function() { var array_ids = []; $('.add').click(function() { array_ids.push($(this).parent().siblings('.row_id').html().trim()); alert(array_ids); }); $('.show').click(function(e) { //e.preventDefault(); var jsonString = JSON.stringify(array_ids); $.ajax( { method: 'POST', url: 'addsale.php', data: {data : jsonString}, cache: false, dataType: "json", success: function() { console.log(data.reply); alert(data.reply); } }); }); });

并且addsale.php

And addsale.php

if(isset($_POST['push'])) //tried it commenting also! { $data = array(); $data = json_decode(stripslashes($_POST['data'])); foreach($data as $d){ echo $d; } }

任何人都可以告诉我访问数组时缺少什么并从addsale.php获取html到当前页面?

Can anyone tell me what is missing to access the array and get the html from addsale.php to current page?

推荐答案

$(document).ready(function() { var array_ids = []; $('.add').click(function() { array_ids.push($(this).parent().siblings('.row_id').html().trim()); alert(array_ids); }); $('.show').click(function(e) { //e.preventDefault(); //prefer parse function var jsonString = JSON.stringify(array_ids); $.ajax( { method: 'POST', url: 'addsale.php', data: {"data" : jsonString}, cache: false, dataType: "json", //e is the response text from your PHP code success: function(e) { //I don't know why this code //console.log(data.reply); //alert(data.reply); } }); }); });

在PHP代码中尝试

if(isset($_POST['data'])) //tried it commenting also! { $data = array(); $data = json_decode(stripslashes($_POST['data'])); foreach($data as $d){ echo $d; } }

更多推荐

无法从jquery访问数组

本文发布于:2023-10-12 02:52:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483541.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!