如何从codebehind发送数据到javascript文件? [英] how to send a data from codebehind to javascript file?

查看:48
本文介绍了如何从codebehind发送数据到javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做。在mysql数据库中有一个播放列表数据库表。它有标题,艺术家,mp3网址列。

我想从数据库后面的代码中获取这些网址将动态发送javascript文件。



我的javascript文件



I want to do like that.there is a playlist database table in mysql database.it has title,artist,mp3 url column.
I want to take these urls from code behind from database and will send javascript file so dynamically will be.

my javascript file like that

var myPlaylist = [

    {
        mp3:'http://3.s3.envato.com/files/10407161/preview.mp3', hereeeeeeee
        oga:'music/5.ogg',
        title:'Missing You', hereeeee
        artist:'Dejans', hereeeeeee
        rating:5,
        buy:'#',
        price:'17',
        duration:'5:25',
        cover:'music/180x180.jpg'
    },
    {
        mp3:'http://3.s3.envato.com/files/54178721/preview.mp3', hereeee
        oga:'music/4.ogg',
        title:'Midnight In Tokyo', hereeeee
        artist:'BlueFoxMusic', hereeeee
        rating:4,
        buy:'#',
        price:'17',
        duration:'2:51',
        cover:'music/180x180.jpg'
    },





我想从codebehind mp3发送:'xxxxxxxx.mp3'

标题:'yyyyyy'
这个javascript文件的


我该怎么办?



I want to send from codebehind mp3:'xxxxxxxx.mp3'
title:'yyyyyy'
to this javascript file
how can I do?

推荐答案

如果有人希望将数据从代码传递给javascript,那么使用WebMethod和PageMethod,当我们必须在代码后面创建webmethod时,使用WebMethod和PageMethod作为核心ajax,返回类型如下所示:





1.使用PageMethod技术在Javascript中调用Web方法:



Code Behind Page:

------------------------------------------ -----------------

步骤1:在页面后面的代码中创建一个Web方法


[WebMethod]

public static int GetValue()

{

int no = 10;

返回否;

}



步骤2:使用PageMethod技术为调用web方法创建javascript函数



函数GetCodeBehind_Value()

{

PageMethods.GetValue(onsucess,onerror);

}





//这两种方法通常用于处理javascript GetCodeBehind_Value()方法,返回结果值为onsucess(result) 方法如果成功调用其他方法然后返回onerror(result)方法的值。

功能onsucess(结果)

{

提醒(结果);

}



函数onerror(结果)

{

alert(result);

}





注意:Plz使用ScriptManage和enamblepageload方法为真。



If any one wants to be pass data from code behind to javascript then use WebMethod and PageMethod which normaly working as like core ajax when we have to create webmethod at code behind with return type as writen bellow code:


1. Call Web Method in Javascript using PageMethod technique:

Code Behind Page:
-----------------------------------------------------------
step 1: Create one Web Method in code behind page

[WebMethod]
public static int GetValue()
{
int no=10;
return no;
}

step 2: Create javascript function for call web method using PageMethod technique

function GetCodeBehind_Value()
{
PageMethods.GetValue(onsucess,onerror);
}


// These both method is normally used to handling javascript GetCodeBehind_Value() method which is return result value of "onsucess(result)" method if method is sucessfully called other then return value of "onerror(result)" method.
function onsucess(result)
{
alert(result);
}

function onerror(result)
{
alert(result);
}


Note: Plz use ScriptManage and enamblepageload method true.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
   </asp:ScriptManager>





我希望它会帮助你.......: - )



I hope it will help you....... :-)


这篇关于如何从codebehind发送数据到javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆