Php 为什么jquery不能使用codeigniter正确发布?
我试图在我的php处理程序页面上发布一个变量,告诉php是否向数据库中添加某个表单字段的数据,但出于某种原因,我的post函数不会发布任何内容。我使用的是codeigniter框架,用于php方面的东西,jquery用于JavaScript方面的东西。我想这可能与我作为要发布的页面传递的URL有关,以感觉它不是.php页面或类似的页面,但我不确定。任何帮助都将不胜感激Php 为什么jquery不能使用codeigniter正确发布?,php,javascript,jquery,function,post,Php,Javascript,Jquery,Function,Post,我试图在我的php处理程序页面上发布一个变量,告诉php是否向数据库中添加某个表单字段的数据,但出于某种原因,我的post函数不会发布任何内容。我使用的是codeigniter框架,用于php方面的东西,jquery用于JavaScript方面的东西。我想这可能与我作为要发布的页面传递的URL有关,以感觉它不是.php页面或类似的页面,但我不确定。任何帮助都将不胜感激 $('form').submit(function() { if(new_g
$('form').submit(function() {
if(new_gal) {
if(name_valid && description_valid && gal_name_valid && gal_description_valid) {
// return the new gal info to php
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'TRUE'});
return true;
} else {
return false;
}
} else if (name_valid && description_valid)
{
// return the id of the gal to php and tell php not to add the info in the new gal section.
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'FALSE'});
return true;
} else {
return false;
}
非常感谢所有花时间尝试回答这个问题的人 您的代码使用localhost。将其更改为您的网站。Javascript仅在客户端而不是服务器上执行。尝试:
$('form').submit(function() {
if(new_gal) {
if(name_valid && description_valid && gal_name_valid && gal_description_valid) {
// return the new gal info to php
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'TRUE'});
return true;
} else {
return false;
}
} else if (name_valid && description_valid)
{
// return the id of the gal to php and tell php not to add the info in the new gal section.
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'FALSE'});
return true;
} else {
return false;
}
{'NewGallerry': FALSE}
而不是:
$('form').submit(function() {
if(new_gal) {
if(name_valid && description_valid && gal_name_valid && gal_description_valid) {
// return the new gal info to php
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'TRUE'});
return true;
} else {
return false;
}
} else if (name_valid && description_valid)
{
// return the id of the gal to php and tell php not to add the info in the new gal section.
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'FALSE'});
return true;
} else {
return false;
}
{NewGallerry: 'FALSE'}
无论如何,firebug控制台总是帮助您使用ajax;) 使用相对路径
/index.php/site/photoUploader
在站点
控制器中显示代码。您的jQuery代码看起来fine@webarto:为什么?如果你解释一些事情而不是仅仅说“做这个”,那么评论会更有用。@Juan Mendes,如果它解决了他的问题,我会回答为什么。目前,这是毫无意义的。目前我所要做的只是回显发布的数据,这非常简单。我只是在使用echo$this->input->post('NewGallerry');因此,它应该只是呼应出正确或错误。但我不确定发生了什么。这不必要,JavaScript对象不需要引用其属性。jQuery在将它们序列化为JSON时正确地引用它们。无论如何,firebug控制台总是帮助您使用ajax;)这就是答案:)如果他在本地机器上运行呢?考虑否决投票,因为答案中说Javascript只在客户端执行,而不是服务器上执行,这与问题无关,即使问题是跨域问题,我只是在为网站的开发阶段运行一个测试服务器,这就是为什么,但一旦完成,我会将网站移动到一个web服务器。
$('form').submit(function() {
if(new_gal) {
if(name_valid && description_valid && gal_name_valid && gal_description_valid) {
// return the new gal info to php
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'TRUE'});
return true;
} else {
return false;
}
} else if (name_valid && description_valid)
{
// return the id of the gal to php and tell php not to add the info in the new gal section.
$.post('http://localhost/index.php/site/photoUploader', {NewGallerry: 'FALSE'});
return true;
} else {
return false;
}