doumi7861 2011-07-24 21:25
浏览 40
已采纳

使用Codeigniter AJAX发布问题的jQuery

I've been trying to figure this out, but it seems to be harder than i first thought. However, what I'm trying to do is make an ajax post request, but the POST seems to be empty when I'm sending it.

My HTML File

    <div id="statusUpdate">
        <?php echo form_open(base_url() . 'profile/statusUpdate', array('id' => 'statusUpdateForm', 'name' => 'statusUpdateForm')); ?>
            <input type="text" value="Hva tenker du på?" name="profileUpdate" id="profileUpdate" onfocus="if(this.value == 'Hva tenker du på?')this.value=''" onblur="if(this.value == '')this.value='Hva tenker du på?'" />
            <input type="submit" value="" name="profileUpdateButton" id="profileUpdateButton" />
        <?php echo form_close(); ?>
    </div>

My Javascript

        $('#statusUpdateForm').submit(function() {

        $.ajax({ // Starter Ajax Call

            method: "POST", 
            url: baseurl + 'profile/statusUpdate', 
            data: $('#statusUpdateForm').serialize(),
            success: function(data) { 
                alert(data);
            }

        });

        return false;

    });

My PHP (Some of my medhod in the controller)

    // Check if the input is a ajax request
    if($this->input->is_ajax_request()) {
        echo $_POST['profileUpdate'];
    }

Notice, when i put echo "Hello World" etc in the controller, i do get "Hello World" in the alert box from the javascript.

I've also tried a var_dump on $_POST and it returns array(0){} When I'm trying to output the specific $_POST['profileUpdate'] variable i get an error like this,

enter image description here

I've also done a alert from the seralize function i JS, this is what i got,

enter image description here

Is there anyone who know how i can fix this problem?

  • 写回答

2条回答 默认 最新

  • drmlxgmqn18198265 2011-07-24 21:46
    关注

    Try changing method to type.

    I'm guessing the script is performing a GET request, which is the default setting when using ajax(), instead of a POST request. Like this:

    $.ajax({ // Starter Ajax Call
    
            // "method" isn't an option of $.ajax
            // method: "POST", 
            type: "POST", 
    
            url: baseurl + 'profile/statusUpdate', 
            data: $('#statusUpdateForm').serialize(),
            success: function(data) { 
                alert(data);
            }
    
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路