1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-26 00:50:49 +00:00

avoid error when the callback function not exisit

This commit is contained in:
maxin[马鑫] 2016-07-15 19:13:35 +08:00
parent 56dc9bf622
commit 8099a81b7a

View File

@ -208,7 +208,8 @@ func (output *BeegoOutput) JSONP(data interface{}, hasIndent bool) error {
if callback == "" {
return errors.New(`"callback" parameter required`)
}
callbackContent := bytes.NewBufferString(" " + template.JSEscapeString(callback))
callback = template.JSEscapeString(callback)
callbackContent := bytes.NewBufferString(" if(window." + callback + ")" + callback)
callbackContent.WriteString("(")
callbackContent.Write(content)
callbackContent.WriteString(");\r\n")