0

Ok. I have this script below which with slight modification works perfectly for sending 3 of the 4 parameters that I need to post cross-domain style. I am using jQuery's post method with jsonp formatting to make this possible.

I am trying to figure out how to pass in a variable to this method as a parameter and I've tried a ton of variations. Who can help? How do I do this?

<script type="text/javascript">
$(document).ready(function(){
var randomVariable = "Something That Changes in Other Functions";

$.post("urlWithDifferentDomain", {"PropertyWithVariableValue" : randomVariable,
"login":"moreInfo",
"x":1,
"y":2},

function(data){
alert(data.x + "," + data.y + " : " + data.message);
//do something with data here
},'jsonp'
);
});
</script>
  • forget `document.ready` – Dipesh Parmar Apr 24 '13 at 06:01
  • It means you have to put that block of code inside `$(document).ready(function(){ // put your code in here })` – vher2 Apr 24 '13 at 06:06
  • Oh I'm not worried about calling the function. The function is being called. The issue is that I can't figure out how to pass a variable in a JSON object in a jQuery.Post method. This was just an excerpt that I ripped out of my function block. – Mike Garner Apr 24 '13 at 06:08
  • @Ambrosia What do you mean there? – Mike Garner Apr 24 '13 at 06:10
  • I am specifically using jsonp because it is the only method that I know of cross-domain posting. – Mike Garner Apr 24 '13 at 06:12
  • You want to control the name of `variablePropertyIWantToSend`, or just it's value? – Codrin Eugeniu Apr 24 '13 at 06:15
  • @CodrinEugeniu Eugeniu Just the value sorry. – Mike Garner Apr 24 '13 at 06:17
  • Did you put `?callback=?` in your url? – vher2 Apr 24 '13 at 06:18
  • No, but I'm not having issues with the function actually sending data, I just don't know how to pass a variable into a json Object and I have been searching for hours it feels like. – Mike Garner Apr 24 '13 at 06:19
  • You can refer to this question [http://stackoverflow.com/questions/2699277/post-data-to-jsonp](http://stackoverflow.com/questions/2699277/post-data-to-jsonp) – vher2 Apr 24 '13 at 06:42
  • "I am specifically using jsonp because it is the only method that I know of cross-domain posting." What? JSONP doesn't somehow allow you to do a cross-domain POST. JSONP is just a way of wrapping JSON in a JavaScript function call, so it can be loaded with a ` – Michael Geary Apr 24 '13 at 06:42

0 Answers0