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 8539383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:21:11+00:00 2026-06-11T11:21:11+00:00

I have a form that asks the user to enter their Google Analytics code

  • 0

I have a form that asks the user to enter their Google Analytics code in a textarea. I then pass this string into ajax post and receive an error saying that I am passing an invalid object. (I am not pasting the whole error message here as it is quite long..)

The Google Analytics code, as expected, is in the form of following;

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'some_number']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

And I use this to post to server:

        $.ajax({
            type: "POST",
            url: "Settings.aspx/setStats",
            data: "{'skey': 'ga_code', 'sval':'" + el.val() + "'}",
            dataType: "json",
            contentType: "application/json; charset=utf-8"
        }); // el.val() being the google analytics code..

How can I post this without the error? Also, I will need to get it as well, when the user needs to update it.. Will the same problem arise when receiving it too?

  • 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-11T11:21:12+00:00Added an answer on June 11, 2026 at 11:21 am

    Your object as it stands is not so; it is a string, you are passing a string as an object.. try the following:

    data: { skey: 'ga_code', sval: el.val() },
    

    Usually objects are converted into query strings, as is said on the documentation page, but since you are passing a string to the converter, I believe it is not going to work.

    Update:

    It would appear I was a bit wrong; the above is not valid json, the following should work, as a correction to the above:

    data: { "skey": "ga_code", "sval": el.val() }
    

    Keys and values must be double-quoted, from what I am reading, though I’m a bit confused, as I have used json like I first gave you with no problems what-so-ever. Lastly, I would recommend this site to test if your JSON is valid.

    If that still doesn’t work, then I would recommend changing your contentType to the following:

    "application/x-www-form-urlencoded; charset=utf-8"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic form that asks the user to enter some text in
I have a form that asks users to enter a start and end time
I have made a form that asks the user to put in first name
At http://localhost/tmp/ I have a form that asks for the user and password (authentication).
I have a form that accepts user input and asks them to upload a
I have a form that asks the user to press the Q key 3
I currently have form that checks if a user has unsubmitted changes when they
I have a form that has label values that I would like to pass
I have a form that the user submits and returns a result, but it
I have a form that i want an administrator to fill out, then click

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.