admin管理员组文章数量:1025748
How to create list of object in jquery ? Example:
Object name: rowdataObject having properties.
NOw, i want to create list of rowdataObject and pass to MVC.
Please suggest me how to create list of object in javascript and pass as argument in controller.
Thanks
How to create list of object in jquery ? Example:
Object name: rowdataObject having properties.
NOw, i want to create list of rowdataObject and pass to MVC.
Please suggest me how to create list of object in javascript and pass as argument in controller.
Thanks
Share Improve this question edited Mar 8, 2014 at 8:35 tereško 58.5k25 gold badges100 silver badges150 bronze badges asked Jan 29, 2014 at 13:05 dsidsi 3,36914 gold badges66 silver badges109 bronze badges 1- This question is a bit underrated for this site, but I'll attempt to give you a small example. Keep in mind for future use tho, we generally like to see "what you have tried" first. – SpYk3HH Commented Jan 29, 2014 at 13:25
1 Answer
Reset to default 3<html>
<head>
<script type="text/javascript">
$(function() { // this is jQuery's version of `document.onload = function` which basically means, "start doing this when page is loaded"
// an Object in jQuery is extremely simple in nature
var obj = {}; // this is officially an object
// add to the object by simply creating properties
obj.prop1 = "This property is a string";
// add inner objects just as easy
obj.class1 = { prop1: "This inner object now has it's own property" }
// to pass this to a "controller" in jQuery, you will use a form of $.ajax
$.ajax({ // here you start creating ajax options
type: 'POST', // makes this retrievable via POST on server side, exp: $_POST['keyName']
data: JSON.stringify({ keyName: obj }), // easiest way to send data as key|value
url: 'http://www.example.' // here you need the url to your controller
}) // now, use jQuery chainability to see results returned from controller
.done(function( data, textStatus, jqXHR ) {
// this function will fire only if the controller makes a successful return
/* do work, exp: */
console.log(data); // this would show the results of what the controller returned in your browser's developer console
})
})
</script>
</head>
<body>
References
- JS Object
- $.ajax
- jQuery's Chainability
- JSON
How to create list of object in jquery ? Example:
Object name: rowdataObject having properties.
NOw, i want to create list of rowdataObject and pass to MVC.
Please suggest me how to create list of object in javascript and pass as argument in controller.
Thanks
How to create list of object in jquery ? Example:
Object name: rowdataObject having properties.
NOw, i want to create list of rowdataObject and pass to MVC.
Please suggest me how to create list of object in javascript and pass as argument in controller.
Thanks
Share Improve this question edited Mar 8, 2014 at 8:35 tereško 58.5k25 gold badges100 silver badges150 bronze badges asked Jan 29, 2014 at 13:05 dsidsi 3,36914 gold badges66 silver badges109 bronze badges 1- This question is a bit underrated for this site, but I'll attempt to give you a small example. Keep in mind for future use tho, we generally like to see "what you have tried" first. – SpYk3HH Commented Jan 29, 2014 at 13:25
1 Answer
Reset to default 3<html>
<head>
<script type="text/javascript">
$(function() { // this is jQuery's version of `document.onload = function` which basically means, "start doing this when page is loaded"
// an Object in jQuery is extremely simple in nature
var obj = {}; // this is officially an object
// add to the object by simply creating properties
obj.prop1 = "This property is a string";
// add inner objects just as easy
obj.class1 = { prop1: "This inner object now has it's own property" }
// to pass this to a "controller" in jQuery, you will use a form of $.ajax
$.ajax({ // here you start creating ajax options
type: 'POST', // makes this retrievable via POST on server side, exp: $_POST['keyName']
data: JSON.stringify({ keyName: obj }), // easiest way to send data as key|value
url: 'http://www.example.' // here you need the url to your controller
}) // now, use jQuery chainability to see results returned from controller
.done(function( data, textStatus, jqXHR ) {
// this function will fire only if the controller makes a successful return
/* do work, exp: */
console.log(data); // this would show the results of what the controller returned in your browser's developer console
})
})
</script>
</head>
<body>
References
- JS Object
- $.ajax
- jQuery's Chainability
- JSON
本文标签: javascriptHow to create list of object in jqueryStack Overflow
版权声明:本文标题:javascript - How to create list of object in jquery? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745640076a2160693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论