473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

AJAX sending wrong information - any idea why?

I have a question that you will probably be able to answer in a snap, though it has been a constant issue of mine for over a day.

With my PHP script, I produce a variable

Expand|Select|Wrap|Line Numbers
  1. var information1 = 'ip=127.0.0.1&port=80';
When I try to use this variable in my AJAX script, this is the result being sent to my server -

checkStatus.php?information1

Now, as far as I can see, that isn't supposed to happen, its supposed to send the contents of the variable "information1".

This is my script for the AJAX

Expand|Select|Wrap|Line Numbers
  1. $.ajax({
  2. url:'inc/checkStatus.php',
  3. data: currentData,
  4. type: "GET",
  5. cache: false,
this is the currentData variable -

Expand|Select|Wrap|Line Numbers
  1. var currentData = "information" + number;
the number variable is just 1.

To sum this message up -

The way I wrote the "currentData" variable, is it correct? If not, what is the correct way of writing it, and if it is, do you have any idea why AJAX is sending "information1" as text instead of a variable?

Any help is appreciated as always, thank you in advance!
Feb 4 '12 #1

✓ answered by Rabbit

Don't use the string at all. Just use the variable name.

4 1490
Rabbit
12,516 Expert Mod 8TB
That's because when you put double quotes around a string, it's treated as a string. Not a variable. "information1" is just a string. Just because you so happen to name a variable the same as what's in a string doesn't mean that the value of the variable will be placed in the string.
Feb 5 '12 #2
Do you know how I could avoid making it a string? From what you said it means I need it as a variable.

I searched around and found a method that apparently works, it said to use "window" and some square brackets, although I do not know how I would implement this into my script, can you help me with this please?
Feb 5 '12 #3
Rabbit
12,516 Expert Mod 8TB
Don't use the string at all. Just use the variable name.
Feb 5 '12 #4
Okay I have no idea how I could possibly do that, I have some new code that may be easier to understand what I mean..

Expand|Select|Wrap|Line Numbers
  1. function processServers() {
  2.     var amountOfServers = 5;
  3.     var i=1;
  4.     while (i <= amountOfServers) {
  5.         'checkServer'+i+'()';
  6.         i++;
  7.     }
  8. }
  9.  
instead of
'checkServer'+i+'()';
I need it to say
checkServer1(), then on the next loop it would say checkServer2() and so on..

I do not know if this is even possible, can you please help? I am not a javascript coder.

----------------------------------------------
----------------------------------------------

Thank you for all your help Rabbit, after several more hours of googling and rephrasing my search, I finally found the help I needed!

Turns out I had to use the square brackets afterall.
Feb 5 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: G Matthew J | last post by:
interesting "signal vs. noise" blog entry: http://37signals.com/svn/archives2/whats_wrong_with_ajax.php
2
by: Cederstrom | last post by:
Hello Group, I have created an ASP.NET page. The page consist of the following items: - Button A - Button B - UserControl When I press Button A, I execute the following code: ViewState =...
0
by: David Hearn | last post by:
I have a web application that has a standard form on it (Name, Address, City, etc). I am having a problem that I have never experienced before. If two users are on the site simultaneously (they can...
0
by: Burak | last post by:
Hello, I know of two main ways by which structured information is sent : - web services - sending a flat file Is there any other way, possibly tcp-ip based, to send structured information?...
2
by: Niko | last post by:
Hi I have a big problem with some browser setting wrong ASP.NETSessionid in a cookie, and the result is that asp.net 1.1 always assigns new session to the client. I checked what is going on and...
5
by: Ruso | last post by:
I am using ASP to make an application. What I want right now - is to make the self updating list of the users online - based on thier cookies. In my opinion all seems to be writen well with it's...
12
by: Aggelos | last post by:
Hello everyone, I am trying to emulate sort of a Payment Gateway. A user makes an order and then when he checks out he gets transfered to the HTTPS page to enter his details. At the moment I am...
5
by: Raistlin Majere | last post by:
with css label is on the left and labelled is on the right without css, label is on the top and labelled is on the bottom If modify.php is: <form action="modify2.php" method="post"> <div...
2
by: Mike | last post by:
Hi ASP.NET gurus, I am a newbie, so please help me. I have a Grid with paging on it. If I go to some other page and when I press refresh icon on the IE I get this message. The page cannot be...
1
by: Sourabh Raizada | last post by:
Hi i'm trying to reload a page using "javascript:history.go(0);". The page consists of some cascading dropdowns implemented using ajax which also invoke gridviews. Now if i try to reload before...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.