2012-01-31 131 views
0

我正在为复选框树实现jQuery Easy UI插件。从我的操作类加载节点数据时遇到问题。 url属性似乎不接受参数 -如何在jQuery中传递url参数

如果我给url: '/webapp/fetchData'我能够获取数据。但如果我给

url: '/webapp/fetchData?nodeId='+nodeId 我的操作类无法获取nodeId参数。 任何解决方案?

编辑码从留言移植:

onExpand: function(node) { 
    alert("inside expand"); 
    var nodeId = node.id; 
    url: '/webapp/fetchdata?nodeId='+nodeId ; 
} 
+0

请发表您的代码。 – 2012-01-31 14:30:10

+0

以下是全部功能: onExpand:function(node){alert(“inside expand”); var nodeId = node.id; url:'/ webapp/fetchdata?nodeId ='+ nodeId; } – user1126136 2012-01-31 14:59:06

+0

在你的更新代码中,这行不做任何事情:'url:'/ webapp/fetchdata?nodeId ='+ nodeId;'它所做的只是创建一个[label](https://developer.mozilla.org/en/) JavaScript/Reference/Statements/label)称为'url',然后连接两个字符串,并对结果不做任何处理。我认为你需要展示更多的代码才能获得有意义的答案。 – 2012-01-31 15:59:17

回答

0

试试这个:

使用POST

function DoAction(id, name) 
{ 
$.ajax({ 
    type: "POST", 
    url: "someurl.php", 
    data: "id=" + id + "&name=" + name, 
    success: function(msg){ 
       alert("Data Saved: " + msg); 
       } 
}); 
} 

使用GET

function DoAction(id, name) 
{ 
$.ajax({ 
     type: "GET", 
     url: "someurl.php", 
     data: "id=" + id + "&name=" + name, 
     success: function(msg){ 
       alert("Data Saved: " + msg); 
       } 
}); 
} 
+0

我正在使用Easy UI插件fir复选框树。所以,他们已经定义了他们自己的'数据'属性,所以他不会工作。 – user1126136 2012-01-31 15:00:58

+0

如何将“URL”代码包装在括号中,有所作为? url:('/ webapp/fetchdata?nodeId ='+ nodeId); – Downpour046 2012-01-31 15:44:13

+0

nope ...支架选项也不起作用... – user1126136 2012-02-01 06:48:31

0

这里是什么对我的作品:

解决方案1:从静态HTML 的javascript:在发送方:

function onBeforeLoad (node, data) 
{ 
    data.Name=name; 
} 

HTML在发送方:

<ul id="ScriptTree1" class="easyui-tree" lines="true" data-options="onBeforeLoad:onBeforeLoad, lines:true, processData:false" url="someural.php"/> 

解决方案2:来自动态代码: HTML

<ul id="ScriptTree2" class="easyui-tree" animate="true"></ul> 

JavaScript函数触发任何具体事件:

function filltree() 
{ 
$('#ScriptTree2').tree 
({ 
     dataType:'json', 
     method:'POST', 
     lines: true, 
     processData:false, 
     onBeforeLoad: function (node,param) { param.Name=name; return true;}, 
     onLoadError: function (dom) 
      { 
       if (!String.prototype.trim) 
       { 
        String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');}; 
       } 

       var sResponse = new String (arguments[0].responseText); 

       alert ('Compl: ' + arguments[1] + ' ' + arguments[2].description + ' ' + arguments[2].name + '\r\nAnswer:\r\n' + sResponse.trim() + '\r\nQuery: \r\n' + decodeURIComponent(arguments.caller.caller.caller[0].data)); 

       return true; 
      }, 
     url:'someurl.php' 
    }); 
} 

和被调用脚本: someurl.php

<? 
if ($_POST['Name'] != '') {$Name=$_POST['Name'];}  else {$Name='';}; 

if ($_POST) 
{ 
    $kv = array(); 
    foreach ($_POST as $key => $value) 
    { 
    $kv[] = "$key=$value"; 
    } 
    $query_string = join(" | ", $kv); 
} 

echo '[{"id":100,"text":"params","state":"open","children":[{"id":104,"text":"query_string: '.$query_string.'","state":"open"}]}]'; 
?>