2015-10-13 71 views
0

提交表单后,我引导到一个空白页,显示一些JSON数据,如:解析JSON和替代HTML

一些错误

{"status":0,"message":"some error message here"} 

或成功

{"status":1,"message":"You have been signed up!"} 

我希望将span元素的内容替换为json数据中的消息。

span元素:

<span class="ladda-label" id="notice">Get notified!</span> 

我的脚本位于我的jQuery后是如下

<script> 
$(document).ready(function() { 
    $.ajax({ 
    dataType: 'json', 
    success: function(data) { 
    var prices = data.message; 
    $('#notice').html(data.message); 
} 
    }); 
}); 
</script> 

我很有信心,我没有做一个正确的事情在这里。

+0

我不明白的问题,你能解释一下吗?你可以把其他代码? –

+0

我希望将span元素的内容替换为json数据中的消息。 – rhill45

+0

你的Ajax请求中没有url和方法 –

回答

1

...更加小心)

<script> 
    $.ajax('/my-data-url',{ 
    dataType: 'json', 
    success: function(data) { 
    var prices = data.message; 

    //$('#notice').text -> html(message.data !!! -> data.message); 

    $('#notice').html(data.message); 
    }, 
    error: function() { 
    console.log('connection error') 
    } 
    }); 
</script> 
+0

我仍然只用我的json数据得到白色法师(但你确实摆脱了我的文本编辑器警告我已经发布了我的当前脚本 – rhill45