2013-05-30 68 views
0

我必须给我一个PHP的链接,我可以用得到的输出:Ajax调用JSP页面

{富: “fooName”,fooLast: “fooLastName”}

我希望通过Ajax使用在JSP文件中此输出

我的剧本是这样的

function loadEmpName(empId){ 
       var urlpath = "http://mysite.com:8080/searchByUid?"+empId; 
       $.ajax({ 
        type: "GET", 
        url: urlpath, 
        dataType: "html", 
        contentType: "application/html; charset=utf-8", 
        success: function(result) { 
//success here (most probably output to a <div> the result 

        }, 
        error: function(error){ 
         //errors here 
        } 
       }); 
      } 

即时消息没有得到任何错误,但我不是获得所需的输出。这甚至有可能开始?

我读不能够做一个跨域Ajax调用,我想知道是否这是

+1

'“http://mysite.com:8080/searchByUid?”+ empId;'。这里有没有特意的文件扩展名? – christopher

+0

我认为是这样,它返回一个字符串 – newbjava

回答

1

你混淆JSP使用JavaScript的情况?只是指出。 你可以简单地做到这一点使用JavaScript像这样:

var strJSON = '{foo:"fooName",fooLast:"fooLastName"}'; 
var objJSON = eval("(function(){return " + strJSON + ";})()"); 
alert(objJSON.foo); 
alert(objJSON.fooLast); 

对于JSP检查这个link

+0

我不知道你在这里建议什么,我想输出一个字符串从一个PHP链接到一个jsp页面我通过使用ajax把该PHP的响应放在一部分我的jsp页面。 – newbjava