2012-03-17 147 views
0
function saveMe() { 
    var strValues = ""; 
    var boxLength = document.choiceForm.choiceBox.length; 
    var count = 0; 
    if (boxLength != 0) { 
     for (i = 0; i < boxLength; i++) { 
      if (count == 0) { 
       strValues = document.choiceForm.choiceBox.options[i].value; 

      } 
      else { 
       strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value; 
      } 
      count++; 
     } 
    } 
    if (strValues.length == 0) { 
     alert("You have not made any selections"); 
    } 
    else { 
     $.post("rolGridPermition.php", { 
      rolId: strValues 
     }); 
    } 
}​ 

在此代码$ .post函数之间其他paranthesis不起作用...有什么问题吗?谁能帮我?

+0

你试图找到一个解决方案,或解决_why_它不工作?检查你的浏览器的错误控制台,并确保它发送到实际功能的PHP脚本。 – Bojangles 2012-03-17 22:10:37

+0

加载资源失败:服务器响应状态为404(Not Found) – 2012-03-17 22:12:00

+0

这是问题所在?什么意思...我是新的php&js – 2012-03-17 22:12:33

回答

0

使用URL正确,

$.post("http://yourdomain/rolGridPermition.php", {rolId: strValues }, function(data) { 
    // code here 
}); 

无法加载资源:服务器与404状态(未找到)意味着PHP文件不在服务器或URL是不正确的回应。

+0

404(找不到)错误是因为一个.css文件...我也尝试了完整路径...但它没有工作.. :( – 2012-03-17 22:25:15

+0

你期望从服务器得到什么结果作为$ .post的响应请求?你有没有在你的php文件中回显任何内容,并且你添加了一个回调函数来处理响应? – 2012-03-17 22:27:45

+0

它传递了一个参数,就像你看到的...在rolGridPermition.php中,这个参数将记录在数据库中......但是没有通过 – 2012-03-17 22:29:30

0

如果你的脚本中包含jQuery,这应该可以工作。

$.post("rolGridPermition.php", { rolId: strValues},function(result){ 
    alert(result); 
}); 

请记住,由于跨域策略,您无法拨打到不同域中的页面。仍然可以做一些黑客来完成它(使用jspnp作为数据类型)