dongliantong3229 2014-10-16 14:02
浏览 206
已采纳

未捕获的TypeError:无法设置未定义的属性“display”

I am in the process of migrating an existing platform to a new server. I am taking the opportunity to upgrade PHP ect and standardise/debug the code as the previous maintainers have had different standards.

I have opted for PHP version 5.4.33 for now, once I have managed to move everything over to mysqli I will look to go to a more recent version. I didnt think anything server side would make a difference to AJAX/JS? As far as I am aware is it not client side?

Since I have moved the code over I am having issues with AJAX/JS. I am not the greatest at AJAX/JS and could use some assistance please. Even though every submit works differently through the entire platform I do not want to remove the AJAX/JS that already exists. I will most likely use it as an opportunity to how to use it as it makes end user experience smoother.

Using Chrome to debug I am receiving the following error on clicking the Save button:

Uncaught TypeError: Cannot set property 'display' of undefined
email_user
onclick

This is the Save button code

<span id="loading" style="color: red; font-size: x-small; display: none; text-decoration: blink;">Loading... Please wait..</span><input type="button" value="Save" class="save" onclick="if(validate()){ email_user(); }" />

This is the function code for validate()

function validate() {

    var errorString = "";

    if(isBlank(document.getElementById("forename").value)) {
        errorString += " - Please input a forename
";
    }
    if(isBlank(document.getElementById("surname").value)) {
        errorString += " - Please input a surname
";
    }
    if(isBlank(document.getElementById("company_name").value)) {
        errorString += " - Please select a company
";
    }

    if(document.getElementById("username").value != "" || document.getElementById("password").value != "") {
        if(isBlank(document.getElementById("username").value)) {
            errorString += " - Please input a username
";
        }
        if(isBlank(document.getElementById("password").value)) {
            errorString += " - Please select a password
";
        }
    }

    //if not a solicitor then cases mandatory
    if(document.getElementById("company_role_type_id").value == 2) { 
        if(document.getElementById("other_view_if").value == "") {
            errorString += " - Please select who can view your cases
";
        }
    }
    if(document.getElementById("company_role_type_id").value == 3) { 
        if(document.getElementById("other_view_ea").value == "") {
            errorString += " - Please select who can view your cases
";
        }
    }

    if(errorString) {
        alert('Please correct the following items:-

'+ errorString);
        return false;
    }
    else {

        return true;
    }
}

This is the function code for email_user()

function email_user(){

if(skip_email == true){ $('user').submit(); }

var url  = 'email_user.php';
var params = '?' + $('user').serialize() + '&from_edit=1';

$('loading').style.display = 'inline';

var myAjax = new Ajax.Request(
                    url,
                    {
                            method: 'get',
                            parameters: params,
                            onComplete: show_response
                    });

function show_response(this_request){

//alert(this_request.responseText);

    var reply = this_request.responseText.evalJSON(true);

    if(reply['status'] == false){ var blah = ''; }

    else{ alert(reply['message']); }

//$('loading').style.display = 'none';

    $('user').submit();

    }

}

Thinking about it, maybe it is more to do with the Apache version?? Just in case Apache version is 2.2.15.

Any assistance you guys can give me will be greatly appreciated! If you need any more information please let me know.

Kind Regards,

n00bstacker

  • 写回答

2条回答 默认 最新

  • doutou1922 2014-10-16 14:16
    关注

    As previously stated in comments, your code has some issues, your line (the one that is triggering the error, can be optimized in the following way:

    $('#loading').css("display","inline"); //Selector is ok now... 
    

    In the other hand, I also noticed that you have a second selector $('user') that won´t work. Remember that anything without a dot, or a sharp will be considered as an element selector (loading, and user elements, won´t exist in your document unless you created it.

    Remember:

    $("#myId") //id selector
    $(".myClass") //class selector
    

    If "user" is the form name, the code may work. Remember that you want to catch the form submit event.

    Regards,

    Guillermo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?