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条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置