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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助