Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9067165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:52:56+00:00 2026-06-16T16:52:56+00:00

So basically I have my backbone application making an ajax GET call to my

  • 0

So basically I have my backbone application making an ajax GET call to my slim php app. It expects JSON dataType in return.

$.ajax({
        url: './myroute',
        type: 'GET',
        dataType: "json",
        data: { username: username, password: password },
        success: function(data) {},
        error: function(data) {}
});

In my slim file I have:

$app->get('/myroute', function() use ($app) {

    // all the good stuff here (getting the data from the db and all that)

    $dataArray = array('id' => $id, 'somethingElse' => $somethingElse);

    $response = $app->response();
    $response['Content-Type'] = 'application/json';
    $response->body(json_encode($dataArray));

});

    // Tried with these in the above GET request as well:
    // $app->contentType('application/json');
    // echo json_encode($dataArray);

While my request properly goes through (200), and I properly get my JSON data, the error is because it also returns the full index.php page data as well (which my javascript dataType: “json” does not allow, which triggers the error)

I figured setting the content type to “application/json” would solve this, but it still returns the full page contents as well as the json data.

Edit for reference

I used to have it set up so that Slim would render my html like:

$app->get('/', function () use ($app) {
    // would just have my main page files in home.php instead of index.php
    $app-render('home.php');
});

So that way there, there was no html page data being returned from index.php. But the way pushState is, I have to have my javascript scripts running on index.php, otherwise my pages wont be loaded properly since when they’re requested, the scripts aren’t there to delegate where the route should go.

Any help is appreciated!

Thanks SO!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:52:57+00:00Added an answer on June 16, 2026 at 4:52 pm

    Not familiar with slim framework. looks interesting. Sounds like code keeps running after json is displayed. Maybe try exit;ing the php app after responding with your json?

    $app->get('/myroute', function() use ($app) {
        // all the good stuff here (getting the data from the db and all that)
    
        $dataArray = array('id' => $id, 'somethingElse' => $somethingElse);
    
        $response = $app->response();
        $response['Content-Type'] = 'application/json';
        $response->body(json_encode($dataArray));
        exit();
    });
    $app->run();
    

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to using Backbone and have a very simple application. Basically there are Clients
I'm planning on writing a spine/backbone.js style web application which basically just transfers a
I basically have a class within another class (child). I'm trying to get the
My application is a single page app (backbone.js) and it uses google maps that
I have a collection of models in my Backbone.js application. It's a list of
I am trying to populate instagram images using backbone, I have basically 3 models
I basically have: Public Class Job: MyBaseClass { public virtual string JobInformation {get;set;} ...
Hi all I am creating my first Backbone.js app. It is basically a collection
I basically have a list of contacts in my app, I want to mark
When I run the r.js optimizer over my Backbone.js app, I get this error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.