dongpaipu8394 2010-10-13 17:11
浏览 56

AJAX调用和运行PHP脚本

I have a working PHP script on my server and a HTML page with JavaScript and AJAX which I would like to call and run the PHP script. However, the AJAX responseText is displaying all the PHP code rather than running it. What do I need to do to only get the results of the PHP? Other examples I looked at used the responseText and it seemed to work out well, but not for me :(

Thanks,

elshae

My AJAX code is below...my PHP works fine, it has been tested :)

    function ahah(url) {
               //document.getElementById(target).innerHTML = ' Fetching data...';
               if (window.XMLHttpRequest) {
                 req = new XMLHttpRequest();
               } else if (window.ActiveXObject) {
                 req = new ActiveXObject("Microsoft.XMLHTTP");
               }
               if (req != undefined) {
                 req.onreadystatechange = function() {ahahDone(url);};
                 req.open("GET", url, true);
                 req.send("");
               }
             }  

             function ahahDone(url) {
               if (req.readyState == 4) { // only if req is "loaded"
                 if (req.status == 200) { // only if "OK"
                  var div = document.createElement('DIV');
                  div.innerHTML = req.responseText;
                  document.getElementById('chicken_contentDiv').appendChild(div);
                 } else {
                   " <div> AHAH Error:
"+ req.status + "
" +req.statusText + "</div>";
                 }
               }
             }

             function load(name) {
              ahah(name);
              return false;
              }
<div> + load('./getFiles.php') + </div> //called in a div

Ok here is the new code:

//Some stuff happens here, IMO think it's irrelevant to this issue...

//This is where the AJAX/JQuery calls the php
var info = new OpenLayers.Control.WMSGetFeatureInfo({
                    url: 'http://localhost:8080/geoserver/wms',
                    title: 'Identify features by clicking',
                    queryVisible: true,
                    eventListeners: {
                        getfeatureinfo: function(event){              
                           map.addPopup( new OpenLayers.Popup.AnchoredBubble(
                                "chicken",
                                map.getLonLatFromPixel(event.xy),
                                null,
                                event.text + '<div> Hello Tibet :)</div>' + $('#chicken_contentDiv').load('http://localhost/mapScripts/getFiles.php'), //have also tried localhost:80, no diff

                                null,
                                true

                            ));

                        }

                     }
                });
                map.addControl(info);
                info.activate();

    });
  • 写回答

3条回答 默认 最新

  • duan19740319 2010-10-13 17:21
    关注

    If the response contains actual PHP code, then it is not being processed by the PHP interpreter. Where are you running this? It is obvious that the web server is not properly configured to process PHP files.

    EDIT:

    The line you have:

    event.text + '<div> Hello Tibet :)</div>' + $('#chicken_contentDiv').load('http://localhost/mapScripts/getFiles.php'),
    

    is incorrect.. you don't want to append the outcome of the jQuery function. The output would always be an object. You just want to run that script, which would populate a DIV with an ID of chicken_contentDiv. (is that really the right DIV to put the details in?)

    It should be at the end, after your var info declaration is closed and done.

    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛