Welcome Guest, Not a member yet? Register   Sign In
How can I grab the json object and ignore the rest?
#1

[eluser]jshultz[/eluser]
This is what is happening. I've got a form that lets me create or update a page. When it's creating a page the pageid value is 0. Otherwise, pageid is the value of whatever the page is I'm editing. When I hit submit, a jquery function is listening for the event and serializes the data and sends it off to the controller. The controller hands it off to the model. In the model, depending on whether or not it's a create or update, will determine whether or not a json object is echoed back. Either way, the controller updates the routes file irregardless, because the form could be creating or updating the page. That means, the rank of the page could be updated or a page could be moved to be a child of another page, etc.

The success part of my ajax call is listening to see what data is returned. Specifically, i'm looking for the new pageid of the newly created page. I'll use that to add the list item to the sidebar where the pages are listed. The problem is, not only is the json object getting returned, but an array containing all the pages is getting returned because of the routes file being updated.

Is there a way I can "listen" or grab just the json object and ignore everything else?

Here's a sample of the response I get after a page creation according to firebug:

Code:
[{"pageid":"13","page_name":"test apge 43","page_headline":"New Page Headline Goes Here","page_intro":"","page_content":"<p>\n Insert Page Content Here<\/p>","parentid":"0","templateid":"0","sectionid":"0","userid":"1","siteid":"4556602514ec4a0885a5fa","rank":"0"}]

array(10) {
  ["pageid"]=>
  string(1) "1"
  ["page_name"]=>
  string(5) "index"
  ["page_headline"]=>
  string(18) "Welcome to My Page"
  ["page_intro"]=>
  string(0) ""
  ["page_content"]=>
  string(38) "<p>
Here's some page content.</p>"
  ["parentid"]=>
  string(1) "0"
  ["sectionid"]=>
  string(1) "1"
  ["userid"]=>
  string(1) "1"
  ["siteid"]=>
  string(22) "4556602514ec4a0885a5fa"
  ["rank"]=>
  string(1) "0"
}
array(10) {
  ["pageid"]=>
  string(2) "12"
  ["page_name"]=>
  string(12) "test page 42"
  ["page_headline"]=>
  string(27) "New Page Headline Goes Here"
  ["page_intro"]=>
  string(0) ""
  ["page_content"]=>
  string(33) "<p>
Insert Page Content Here</p>"
  ["parentid"]=>
  string(1) "0"
  ["sectionid"]=>
  string(1) "0"
  ["userid"]=>
  string(1) "1"
  ["siteid"]=>
  string(22) "4556602514ec4a0885a5fa"
  ["rank"]=>
  string(1) "0"
}
array(10) {
  ["pageid"]=>
  string(2) "13"
  ["page_name"]=>
  string(12) "test apge 43"
  ["page_headline"]=>
  string(27) "New Page Headline Goes Here"
  ["page_intro"]=>
  string(0) ""
  ["page_content"]=>
  string(33) "<p>
Insert Page Content Here</p>"
  ["parentid"]=>
  string(1) "0"
  ["sectionid"]=>
  string(1) "0"
  ["userid"]=>
  string(1) "1"
  ["siteid"]=>
  string(22) "4556602514ec4a0885a5fa"
  ["rank"]=>
  string(1) "0"
}
array(10) {
  ["pageid"]=>
  string(1) "4"
  ["page_name"]=>
  string(11) "subpagetest"
  ["page_headline"]=>
  string(13) "Sub Page test"
  ["page_intro"]=>
  string(0) ""
  ["page_content"]=>
  string(65) "<p>
Example data goes here. And it doesn't go here. duh.</p>"
  ["parentid"]=>
  string(1) "0"
  ["sectionid"]=>
  string(1) "1"
  ["userid"]=>
  string(1) "1"
  ["siteid"]=>
  string(22) "4556602514ec4a0885a5fa"
  ["rank"]=>
  string(1) "1"
}
array(10) {
  ["pageid"]=>
  string(1) "5"
  ["page_name"]=>
  string(10) "Contact Us"
  ["page_headline"]=>
  string(10) "Contact Us"
  ["page_intro"]=>
  string(0) ""
  ["page_content"]=>
  string(69) "<p>
This would be a great contact us page. It's pretty cool.</p>"
  ["parentid"]=>
  string(1) "0"
  ["sectionid"]=>
  string(1) "0"
  ["userid"]=>
  string(1) "1"
  ["siteid"]=>
  string(22) "4556602514ec4a0885a5fa"
  ["rank"]=>
  string(1) "2"
}


Messages In This Thread
How can I grab the json object and ignore the rest? - by El Forum - 09-05-2012, 08:39 AM
How can I grab the json object and ignore the rest? - by El Forum - 09-05-2012, 08:49 AM
How can I grab the json object and ignore the rest? - by El Forum - 09-05-2012, 12:47 PM
How can I grab the json object and ignore the rest? - by El Forum - 09-05-2012, 01:58 PM
How can I grab the json object and ignore the rest? - by El Forum - 09-05-2012, 02:01 PM
How can I grab the json object and ignore the rest? - by El Forum - 09-05-2012, 02:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB