php - Jquery: How can I combine two json data objects and post them? -
After that, I have another problem - how do I add two Jason data objects?
The first Jason object,
{"file": {"name": "1024x768.jpg", "type": "image / jpeg", "tmp_name" : "C: \\ wamp \\ tmp \\ php2C2E.tmp", "Error": 0, "Size": 469159}} The second Jason object, < Pre> {"title": "title", "content": "bla bla blah"} $ .post ("process.php", first + second, function (xml) {}); Then I can use this array in print_r ($ _ POST) in process.php : Array ([File] = & Gt; array ([name] => 1024x768.jpg [type] => image / jpeg [tmp_name] => C: \ wamp \ tmp \ phpA1.tmp [error] = & Gt; 0 [Size] = & gt; 469159) [Title] = & gt; Title [Content] => bla bla blah
File is not an array, as you would see it on server side php code = class = "post-text" itemprop = "text"> Looking at it is a JSON object anyway You can combine data objects and try to post. var data1 = {"file": {"name": "1024x768.jpg", "type": "image / jpeg", "tmp_name": "C: \\ wamp \\ tmp \\ php2C2E.tmp "," error ": 0," size ": 469159}}; Var data 2 = {"title": "title", "content": "bla bla blah"} var data = data1; Data.title = data2.title; Data.content = data2.content; $ .post ("process.php", data, function (xml) {}); Alternatively, you can use the jQuery.extend method that merge the content of two or more objects in the first object together. Var file1 = {"file": {"name": "1024x768.jpg", "type": "image / jpeg", "tmp_name": "C: \\ wamp \ \ Tmp \\ php2C2E.tmp "," Error ": 0," Size ": 469,159}}; Var data2 = {"title": "title", "content": "bla bla blah"} $ .post ("process.php", $ .extend ({}, data1, data2), function (xml) {} );
Comments
Post a Comment