gpt4 book ai didi

php - 错误缺失;通过jquery发送序列化xml时jquery中的before语句

转载 作者:行者123 更新时间:2023-12-01 06:16:18 25 4
gpt4 key购买 nike

我在下面代码的 var data =<?php echo serialize($msg);?>; 行上收到此错误。控制台还会引发数据未定义错误。如果在数据两边加引号,那么这个错误就会消失,但第一个错误仍然存​​在。

已编辑

//Raw xml
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);
return $xml;
}
?>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">
</script>
</head>
<body>
<script type="text/javascript"> <?php $msg = searchResults('windows');?>;
var data ="<?php echo serialize($msg);?>";
</script>
<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
url: "script.php",
type: "POST",
data: data,
success: function(){
alert("success");
}
});
return false;
});
</script>
</body>
</html>

我试图查看但无法找出任何问题

这是 script.php

<?php
var_dump($_POST);
?>

这是来自 Twitter 的 xml

var data =O:16:"SimpleXMLElement":5:{s:2:"id";s:43:"tag:search.twitter.com,2005:search/#DIYSe_D";s:4:"link";a:4:{i:0;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"text/html";s:4:"href";s:45:"http://search.twitter.com/search?q=%23DIYSe_D";s:3:"rel";s:9:"alternate";}}i:1;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:20:"application/atom+xml";s:4:"href";s:58:"http://search.twitter.com/search.atom?q=%23DIYSe_D&rpp=100";s:3:"rel";s:4:"self";}}i:2;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:37:"application/opensearchdescription+xml";s:4:"href";s:40:"http://search.twitter.com/opensearch.xml";s:3:"rel";s:6:"search";}}i:3;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:20:"application/atom+xml";s:4:"href";s:84:"http://search.twitter.com/search.atom?q=%23DIYSe_D&rpp=100&since_id=7856019371724800";s:3:"rel";s:7:"refresh";}}}s:5:"title";s:25:"#DIYSe_D - Twitter Search";s:7:"updated";s:20:"2010-11-24T21:53:28Z";s:5:"entry";a:3:{i:0;O:16:"SimpleXMLElement":7:{s:2:"id";s:44:"tag:search.twitter.com,2005:7552404006371328";s:9:"published";s:20:"2010-11-24T21:53:28Z";s:4:"link";a:2:{i:0;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"text/html";s:4:"href";s:50:"http://twitter.com/_smir/statuses/7552404006371328";s:3:"rel";s:9:"alternate";}}i:1;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"image/png";s:4:"href";s:67:"http://s.twimg.com/a/1289849896/images/default_profile_5_normal.png";s:3:"rel";s:5:"image";}}}s:5:"title";s:59:"#DIYse_D DELIVERAB: twitter messages 2_inc 1, 19th OCT 2010";s:7:"content";s:248:"<a href="http://search.twitter.com/search?q=%23DIYse_D" 
onclick="pageTracker._setCustomVar(2, 'result_type', 'recent', 3);pageTracker._trackPageview('/intra/hashtag/#DIYse_D');"><b>#DIYse_D</b></a> DELIVERAB: twitter messages 2_inc 1, 19th OCT 2010";s:7:"updated";s:20:"2010-11-24T21:53:28Z";s:6:"author";O:16:"SimpleXMLElement":2:{s:4:"name";s:13:"_smir (Smeer)";s:3:"uri";s:24:"http://twitter.com/_smir";}}i:1;O:16:"SimpleXMLElement":7:{s:2:"id";s:44:"tag:search.twitter.com,2005:7551711354822656";s:9:"published";s:20:"2010-11-24T21:50:42Z";s:4:"link";a:2:{i:0;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"text/html";s:4:"href";s:58:"http://twitter.com/Babar_Shahzad/statuses/7551711354822656";s:3:"rel";s:9:"alternate";}}i:1;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"image/png";s:4:"href";s:103:"http://a1.twimg.com/profile_images/1090185625/29465_391454998679_533808679_3864564_6071800_n_normal.jpg";s:3:"rel";s:5:"image";}}}s:5:"title";s:58:"#DIYse_D DELIVERAB: twitter messages 2_inc2, 24th OCT 2010";s:7:"content";s:247:"<a href="http://search.twitter.com/search?q=%23DIYse_D" onclick="pageTracker._setCustomVar(2, 'result_type', 'recent', 3);pageTracker._trackPageview('/intra/hashtag/#DIYse_D');"><b>#DIYse_D</b></a> DELIVERAB: twitter messages 2_inc2, 24th OCT
2010";s:7:"updated";s:20:"2010-11-24T21:50:42Z";s:6:"author";O:16:"SimpleXMLElement":2:{s:4:"name";s:32:"Babar_Shahzad (Babar Shahzad Ch)";s:3:"uri";s:32:"http://twitter.com/Babar_Shahzad";}}i:2;O:16:"SimpleXMLElement":7:{s:2:"id";s:44:"tag:search.twitter.com,2005:7550668919283712";s:9:"published";s:20:"2010-11-24T21:46:34Z";s:4:"link";a:2:{i:0;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"text/html";s:4:"href";s:58:"http://twitter.com/Babar_Shahzad/statuses/7550668919283712";s:3:"rel";s:9:"alternate";}}i:1;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"image/png";s:4:"href";s:103:"http://a1.twimg.com/profile_images/1090185625/29465_391454998679_533808679_3864564_6071800_n_normal.jpg";s:3:"rel";s:5:"image";}}}s:5:"title";s:53:"#DIYse_D DELIVERAB: twitter messages 1, 9th OCT 2010";s:7:"content";s:242:"<a href="http://search.twitter.com/search?q=%23DIYse_D" onclick="pageTracker._setCustomVar(2, 'result_type', 'recent', 3);pageTracker._trackPageview('/intra/hashtag/#DIYse_D');"><b>#DIYse_D</b></a> DELIVERAB: twitter messages 1, 9th OCT 2010";s:7:"updated";s:20:"2010-11-24T21:46:34Z";s:6:"author";O:16:"SimpleXMLElement":2:{s:4:"name";s:32:"Babar_Shahzad (Babar Shahzad Ch)";s:3:"uri";s:32:"http://twitter.com/Babar_Shahzad";}}}};

这是我的 json 等效代码,但它不起作用。我把它放在这里是因为很多人(如果不是所有人)都推荐我将 json 添加到此代码中,即 OP,实际上是我想要的,但是 OP 将 xml 发送到 php,因为 json 之前对我不起作用' *此代码不会引发控制台错误,但会输出失败警报 *curl 正在发送结果,我已经在测试 php block 中进行了测试在 HTML 中的 ajax 之前。

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>
<?php
function searchResults($q) {

$host = "http://search.twitter.com/search.atom?q=" . urlencode( $q ) . "&rpp=100";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

//Raw xml
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);
return json_encode($xml);
}
?>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">
</script>
</head>
<body>
<script type="text/javascript"> var msg_top = <?php echo searchResults('windows');?>;
</script>
<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
url: "script.php",
type: "POST",
dataType: "json",
data: msg_top,
success: function(msg){
alert("success");
}
});
alert("failure");
});
</script>
</body>
</html>

最佳答案

尝试一下<罢工>

<罢工>
var data="<?php echo json_encode(serialize($msg));?>";

<罢工>

编辑:抱歉,json_encode()函数会自动将引号添加到字符串中,因此代码应如下所示:

var data=<?php echo json_encode(serialize($msg));?>;


第一个 ; 之后有一些多余的分号( ?> ) ,你应该删除它。

关于php - 错误缺失;通过jquery发送序列化xml时jquery中的before语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4280814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com