Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改php函数并将结果发送到jquery ajax_Php_Jquery_Ajax - Fatal编程技术网

如何更改php函数并将结果发送到jquery ajax

如何更改php函数并将结果发送到jquery ajax,php,jquery,ajax,Php,Jquery,Ajax,我有很多用户通知代码,它做了很多mysql工作,所以需要等待时间。 jqueryajax适用于php文件。 如何使用jquery将php结果发送到网页 当前代码: <? echo db_cache("main_top_naver_cache", 300, "naver_popular('naver_popular', 4)"))?> 想要的代码:但它显示错误。 php函数的结果不会发送到div elment。 htmlspecialchars是无用的 <div id='a'&

我有很多用户通知代码,它做了很多mysql工作,所以需要等待时间。 jqueryajax适用于php文件。 如何使用jquery将php结果发送到网页

当前代码:

<? echo db_cache("main_top_naver_cache", 300, "naver_popular('naver_popular', 4)"))?>
想要的代码:但它显示错误。 php函数的结果不会发送到div elment。 htmlspecialchars是无用的

<div id='a'>
<div id='b'>
<script type="text/javascript">
    $("#test1").html( " <? echo htmlspecialchars(db_cache("main_top_naver_cache", 300, "naver_popular('naver_popular', 4)"))?> " );
</script>
IE调试程序显示错误。。。脚本1015:。。。未完成的sting常量

<script type="text/javascript">
$("#test1").html( " &lt;style&gt;
/* http://html.nhncorp.com/uio_factory/ui_pattern/list/3 */
.section_ol3{position:relative;border:1px solid #ddd;background:#fff;font-size:12px;font-family:Tahoma, Geneva, sans-serif;line-height:normal;*zoom:1}
.section_ol3 a{color:#666;text-decoration:none}
.section_ol3 a:hover,
.section_ol3 a:active,
.section_ol3 a:focus{text-decoration:underline}
.section_ol3 em{font-style:normal}
.section_ol3 h2{margin:0;padding:10px 0 8px 13px;border-bottom:1px solid #ddd;font-size:12px;color:#333}
.section_ol3 h2 em{color:#cf3292}
.section_ol3 ol{margin:13px;padding:0;list-style:none}
.section_ol3 li{position:relative;margin:0 0 10px 0;*zoom:1}
.section_ol3 li:after{display:block;clear:both;content:&quot;&quot;}
.section_ol3 li .ranking{display:inline-block;width:14px;height:11px;margin:0 5px 0 0;border-top:1px solid #fff;border-bottom:1px solid #d1d1d1;background:#d1d1d1;text-align:center;vertical-align:top;font:bold 10px Tahoma;color:#fff}
.section_ol3 li.best .ranking{border-bottom:1px solid #6e87a5;background:#6e87a5}
.section_ol3 li.best a{color:#7189a7}
.section_ol3 li .num{position:absolute;top:0;right:0;font-size:11px;color:#a8a8a8;white-space:nowrap}
.section_ol3 li.best .num{font-weight:bold;color:#7189a7}
.section_ol3 .more{position:absolute;top:10px;right:13px;font:11px Dotum, 돋움;text-decoration:none !important}
.section_ol3 .more span{margin:0 2px 0 0;font-weight:bold;font-size:16px;color:#d76ea9;vertical-align:middle}
&lt;/style&gt;

&lt;div class=&quot;section_ol3&quot;&gt;
    &lt;ol style='text-align:left;'&gt;
  &lt;li class='best'&gt;&lt;span class='ranking'&gt;1&lt;/span&gt;&lt;a    href='http://search.naver.com/search.naver?where=nexearch&amp;query=%B9%AB%C7%D1%B5%B5%C0%FC&amp;sm=top_lve' onfocus='this.blur()' title='무한도전' target=new&gt;무한도전&lt;/a&gt;&lt;span class='num'&gt;+42&lt;/span&gt;&lt;/li&gt;&lt;li class='best'&gt;&lt;span class='ranking'&gt;2&lt;/span&gt;&lt;a href='http://search.naver.com/search.naver?where=nexearch&amp;query=%B1%E8%C0%E7%BF%AC&amp;sm=top_lve' onfocus='this.blur()' title='김재연' target=new&gt;김재연&lt;/a&gt;&lt;span class='num'&gt;+123&lt;/span&gt;&lt;/li&gt;&lt;li class='best'&gt;&lt;span class='ranking'&gt;3&lt;/span&gt;&lt;a href='http://search.naver.com/search.naver?where=nexearch&amp;query=%C0%CC%C7%CF%C0%CC&amp;sm=top_lve' onfocus='this.blur()' title='이하이' target=new&gt;이하이&lt;/a&gt;&lt;span class='num'&gt;+90&lt;/span&gt;&lt;/li&gt;&lt;li &gt;&lt;span class='ranking'&gt;4&lt;/span&gt;&lt;a href='http://search.naver.com/search.naver?where=nexearch&amp;query=%BA%D2%C8%C4%C0%C7%B8%ED%B0%EE2&amp;sm=top_lve' onfocus='this.blur()' title='불후의명곡2' target=new&gt;불후의명곡2&lt;/a&gt;&lt;span class='num'&gt;+87&lt;/span&gt;&lt;/li&gt;  &lt;/ol&gt;

正确的代码

<?
// http://huddak.net/bbs/board.php?bo_table=cm_free&wr_id=3629
function remove_nr($str) {
    $reg_e = array('/\n/', '/\r/', '/\"/', "/<\/script>/i"); 
    $reg_p = array(' ', ' ', '\\"', "<\/SCRIPT>"); 

    return preg_replace($reg_e, $reg_p, $str);
}
?>

<script type="text/javascript">
$("#test1").html( " <? echo remove_nr( trim( db_cache("main_top_naver_cache", 300, "naver_popular('naver_popular', 4)")))?> " ); 
</script>
您可以使用耗时的php代码来加载jquery。
这使您的页面加载变得非常棒。

您可以使用json_encode对数据进行编码,然后使用echo将其发送到jquery,这可能会解决您的问题。

我使用echo将数据显示到网页,而不是将数据发送到其他程序。json_encode是一个很好的函数,但对我来说不是。
<?
// http://huddak.net/bbs/board.php?bo_table=cm_free&wr_id=3629
function remove_nr($str) {
    $reg_e = array('/\n/', '/\r/', '/\"/', "/<\/script>/i"); 
    $reg_p = array(' ', ' ', '\\"', "<\/SCRIPT>"); 

    return preg_replace($reg_e, $reg_p, $str);
}
?>

<script type="text/javascript">
$("#test1").html( " <? echo remove_nr( trim( db_cache("main_top_naver_cache", 300, "naver_popular('naver_popular', 4)")))?> " ); 
</script>