我現在想用ajax的$post給伺服器端傳值,如何擷取ueditor裡的值呢,我的頁面載入代碼如下:
頁面能顯示出來ueditor。
我現在用jq呀js通過id“blog_content”取到的值alert出來全是空,取不到這個值,我如何$post這個值啊。。。。請高手解答
回複討論(解決方案)
1. editor.getContent() 直接用 ueditor對象方法
2.$('#blog_content').val() ,你確定值在blog_content裡
我查了editor的API,我看著有editor.getContent() 這個方法,我也用了,也是空。我不確定值是不是在blog_content裡,用$('#blog_content').val();的值也是空。。。
我查了editor的API,我看著有editor.getContent() 這個方法,我也用了,也是空。我不確定值是不是在blog_content裡,用$('#blog_content').val();的值也是空。。。
那應該是你搞錯對象,找錯
UE.getEditor('editor').getContent() 用這看看
之前剛做過。。。。直接$('#blog_content').val() 就ok了 沒那麼複雜。。。
之前剛做過。。。。直接$('#blog_content').val() 就ok了 沒那麼複雜。。。
那我取出來的值為啥是空呢
我搞錯了。。。這個很久前弄過次。。。我改用別的了 說真還得去看下文檔
引用 2 樓 blackartrock 的回複:我查了editor的API,我看著有editor.getContent() 這個方法,我也用了,也是空。我不確定值是不是在blog_content裡,用$('#blog_content').val();的值也是空。。。
那應該是你搞錯對象,找錯
UE.getEditor('editor').getContent() 用這……
這個方法好用,能取到值了,謝謝。
不過ajax的post提交為啥跳轉了,還在地址欄轉值呢?
http://blog.local/index.php/admin/blog_c/insertBlog?blog_title=&select_category=%E8%AF%B7%E9%80%89%E6%8B%A9%E6%97%A5%E5%BF%97%E5%88%86%E7%B1%BB&blog_content=%3Cp%3Eaa%3Cbr+%2F%3E%3C%2Fp%3E
看看你的 .post 怎麼寫的。。。估計是寫錯了
你用的是什麼ajax包
比如 jquery包的,
$.post(url,{blog_content:....,select_category:...},function(){
alert('完成')
})
url = "http://blog.local/index.php/admin/blog_c/insertBlog"
.post(url,{blog_title:UE.getEditor('editor').getContent()},function(d){});
OK?
看看你的 .post 怎麼寫的。。。估計是寫錯了
$.post("",
{blog_title:blog_title,blog_category:blog_category,blog_content:blog_content},
function(data){
$(".category_list").html(data);
});
提交的一順點我看間firebug裡有提交請求,但是,是紅色的,跳轉後就看不見了
你先直接 alert 要提交各項的 值 是不是你要的。。。雖然笨點,,但一看就曉得哪裡錯了
你先直接 alert 要提交各項的 值 是不是你要的。。。雖然笨點,,但一看就曉得哪裡錯了
alert出來的值沒問題,我每一項都顯示了,都是我想要的值,但是php接收不到post
$_POST['blog_content'],輸出這個,說是變數blog_content未定義。我想應該是post提交沒成功,因為我看到firebug裡有紅色。。。。
有紅色,但是馬上就跳轉到下個頁面了,所以沒法點開看
我也不曉得問題在哪裡。。。。但按自己的情況來說
我就先看 firebug 提交到的 地址有沒有錯 。。。還有到底有底提交到沒。。。
之前弄其他編譯器的時候 也出現過同樣的問題的。。。。
最後就是查看前後代碼 哪裡寫錯了 才解決的。。
用 google chrome 試試
你用的是什麼ajax包
比如 jquery包的,
$.post(url,{blog_content:....,select_category:...},function(){
alert('完成')
})
我用的就是jquery包啊,發代碼了,幫我看下問題出在哪兒了
你把前後的也發下 。。。包括blog_title,blog_category:blog_category,blog_content:blog_content
賦值那裡。。。我現在比較蛋疼。。。研究研究
用 google chrome 試試
剛下了個chrome,看,怎麼變Get了。。。。。。
這個問題我找著原因了,是我的寫法有問題,我在button裡寫了個onclick事件,然後調研了一個方法,但是,我想,$.post只能運行在$(function(){});裡吧,我重寫了一下,給button加了個class,去掉了onclick,然後用jq寫了個click,就好用了,感謝各位的幫忙,結貼了。
引用 2 樓 blackartrock 的回複:我查了editor的API,我看著有editor.getContent() 這個方法,我也用了,也是空。我不確定值是不是在blog_content裡,用$('#blog_content').val();的值也是空。。。
那應該是你搞錯對象,找錯
UE.getEditor('editor').getContent() 用這……
這個方法好用,能取到值了,謝謝。
不過ajax的post提交為啥跳轉了,還在地址欄轉值呢?
http://blog.local/index.php/admin/blog_c/insertBlog?blog_title=&select_category=%E8%AF%B7%E9%80%89%E6%8B%A9%E6%97%A5%E5%BF%97%E5%88%86%E7%B1%BB&blog_content=%3Cp%3Eaa%3Cbr+%2F%3E%3C%2Fp%3E
UE.getEditor('editor').getContent() 這句話是寫在 js 裡面嗎? 我寫這個怎麼也包空呢?求大蝦指教.
var conte = UE.getEditor('editor').getContent();
alert(conte);
我在js裡寫的取不到啊..
問題是對 的處理,如果ajax提交的內容中含有 ,$_POST("name")擷取到得是 前面的值