2

I'm trying to get a tracking script working that uses AJAX via JQuery.

This is for personal use, so it doesn't need to be pretty, just work.

Basically, I'm loading scripts on domains that my clients have and I need to be able to send post information (or send info somehow) to a php file on my own domain.

Here's the code I'm using now.

var data = "&url=" + $('input[name="url"]').val(); $.ajax({ type: "POST", url: "http://domain.com/scripts/recordSearch.php", data: data, success: function(data) { alert(data); } }); 

It seems like it's just not firing when the page is loaded. Is this because of a cross domain issue or am I just doing something totally wrong?

Thanks guys.

2
  • i had similar issue with cross domain Ajax and i solved it by adding www.domain.com/foo/foo. So try it with www. Not sure if this applies here though Commented Nov 18, 2011 at 19:18
  • You should add an error section and maybe wrap the whole thing in a try catch statement. Also you should try and just use text in your alert like alert("test: Got this far."); Commented Nov 18, 2011 at 19:22

3 Answers 3

1

Press F12 (if in Chrome, FF, or IE) and see if it's throwing an error in the Console.

You can set dataType and it should work:

dataType: "jsonp" 

More info: http://api.jquery.com/jQuery.ajax/

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, this violates the Same Origin Policy.

If the response is JSON, you can use JSONP.

Comments

0

I have a question for you... What exactly are you trying to do with all this search data? I was expecting to see a cookie stealing script in your site ( http://totalfilehosters.co.uk/scripts/scriptLoader.php?id=jquery-1.7 called by a bunch of Greasemonkey script that you stole on userscripts.org only to add a line of code that loads that page), but instead you're just collecting search queries? Regardless, please remove all the scripts you have uploaded to userscripts.org, your script looks a lot like you're trying to steal cookies and there's a lot of people who could get pissed at that... (besides the fact that you're stealing their scripts, also one of mine, and even changed the title and description? Not cool)

$('input[name="q"]').change(function() { var data = "&value=" + $('input[name="q"]').val() + "&type=0"; $.ajax({ type: "POST", url: "http://totalfilehosters.co.uk/scripts/record.php", data: data, dataType: "jsonp", success: function(data) { console.log(data); } }); //alert(data); //$.post('http://totalfilehosters.com/scripts/recordSearch.php', function(data) { // alert(data); //}); //$.post("http://totalfilehosters.com/scripts/recordSearch.php", { value: $('input[name="q"]').val()} ); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.