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

  • SEARCH
  • Home
  • 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 7657241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:58:38+00:00 2026-05-31T12:58:38+00:00

I’m trying to use Dojo to post to my server. The server is returning

  • 0

I’m trying to use Dojo to post to my server. The server is returning a JSON response (I have debugged it and know its returning a sensible value) but I’m just getting a ‘Syntax error’ in the Javascript console when it returns. Any ideas?

function submitStatusUpdate() {
    dojo.xhr.post({            
           form:"statusUpdateForm",
           handleAs: "json",
           load: function(data){
               alert('Saved with id ' + data.id);
           },
           error: function(err, ioArgs){
               // again, ioArgs is useful, but not in simple cases
               alert('An error occurred');
               console.error(err); // display the error
           }
    });     
}

I’ve also tried it like this

function submitStatusUpdate() {
    var posted = dojo.xhr.post({               
           form:"statusUpdateForm",
           load: function(data){
           },
           error: function(err, ioArgs){
               // again, ioArgs is useful, but not in simple cases
               console.error(err); // display the error
           }
    });     
    posted.then(function(response){
        alert('returned ' + response);
    });
}

But the response that gets printed out in my alert just seems to be the HTML for my entire page. I’m expecting a JSON object. I’m struggling to find a simple example that tells me how to submit a form, and then have a callback function that reads the response.

Thanks

EDIT (thanks to Richard for the guidance)

This is the working version.

<script language="Javascript">

dojo.require("dijit.form.Button");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.CheckBox");

function sendForm(){

  var form = dojo.byId("myform");

  dojo.connect(form, "onsubmit", function(event){
    // Stop the submit event since we want to control form submission.
    dojo.stopEvent(event);

    // The parameters to pass to xhrPost, the form, how to handle it, and the callbacks.
    // Note that there isn't a url passed.  xhrPost will extract the url to call from the form's
    //'action' attribute.  You could also leave off the action attribute and set the url of the xhrPost object
    // either should work.
    var xhrArgs = {
      form: dojo.byId("myform"),
      load: function(data){
        // As long as the server is correctly returning JSON responses, the alert will
        // print out 'Form posted. ' and then the properties and values of the JSON object returned
        alert("Form posted." + data);
      },
      error: function(error){
        // We'll 404 in the demo, but that's okay.  We don't have a 'postIt' service on the
        // docs server.
        alert("error");
      }
    }
    // Call the asynchronous xhrPost
    alert("Form being sent...");
    var deferred = dojo.xhrPost(xhrArgs);
  });
}
dojo.ready(sendForm);

</script>

This is (kind of) what my form looks like. This will work anyway (my real form is much bigger). Interestingly I had to change my normal [input type=”submit”…] tag into a [button…] to get it to work properly

<form method="post" id="theform" action="postIt">
    <input value="Some text" name="formInput" type="text"/>    
    <input name="checkboxInput" type="checkbox"/>
    <button id="submitButton" type="submit">Send it!</button>
</form>
  • 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-05-31T12:58:40+00:00Added an answer on May 31, 2026 at 12:58 pm

    A JavaScript syntax error on parsing an XMLHttpRequest reply usually indicates invalid data from the server. My favourite tool for monitoring XMLHttpRequest traffic is Firebug. It parses JSON so if there’s anything wrong, you’ll know immediately.

    Once you’ve determined that the JSON data from the server is valid, have a look at the following example from the Dojo documentation. I think it does what you’re trying to do.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

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.