Ajax, JS and "-"'s - javascript

Does anyone know why the ajax statement here won't accept the '-' symbol. I've had trouble with this in the past and had to change a lot of things in the backend of my site to send the "_" instead and it worked. Is there a way to make the ajax script accept the '-' sympbol?
$("#events").append("<img src='"+data[i].event-image+"'></a>");
This code is part of an ajax call to get some JSON data that my website is sending out. "event-image" is the name of my field. The consol throws an error saying can't find "image". So the dash is making the code ignore the first part "event-". Any thoughts on how I could rectify this, other than changing the field on my site to be "_". Let me know, thanks!

- is used for subtraction. You can do it like this though:
data[i]["event-image"]
variable.property is equivalent to variable["property"] in javascript.

Just try using data[i]["event-image"].

Related

Marketo Munchkin js error

I use Muchkin.js enabled in Marketo on my website and somehow getting this error in console - GET https://%20596-oey-331%20.mktoresp.com/webevents/visitWebPage?_mchNc=148758…ard%2F&_mchPc=https%3A&_mchVr=151&_mchHa=&_mchRe=&_mchQp=profile%3Dcreated net::ERR_NAME_NOT_RESOLVED
Any idea what this means and how to fix it? Thanks a lot
it looks like some spaces have crept in to your url in your munchkin code... If you look at the script snippet you pasted in to your template, check if there are any spaces around your instance ID (which would be 596-OEY-331). There shouldn't be any spaces - it should be like Munchkin.init('596-OEY-331') - see if that works!

executing javascript through url

I'm trying to set the value of a textarea on the following page by executing something similar the below javascript:
javascript:alert(document.getElementsByClassName('uiTextareaNoResize uiTextareaAutogrow _1rv DOMControl_placeholder')[0].value='blabla');
This works if I manually enter the code into the address bar on the target page, but I want to pass this argument through a link.. ie...
<a href="/nextpage.php?javascript:alert(document.getElementsByClassName('uiTextareaNoResize uiTextareaAutogrow _1rv DOMControl_placeholder')[0].value='blabla');"
Just wondered if anything like this is possible at all?
You can send the arguments via the url like you would for GET requests. Then have the receiving page parse location.search.
For instance, you can send it like this:
http://example.com/?arg1=foo&arg2=bar
And the receiving page have a script like this:
var queryString = location.search; //?arg1=foo&arg2=bar
You'll have to parse it manually though, removing the ?, split by & then each by =
This is called XSS or Cross-Site-Scripting, and as many comments have already pointed out, it is a security issue. This is why most major browsers do NOT allow it.
However, I believe that some browsers do allow it, for example Opera - although I can't recall exactly which version.
If you are looking to make your own "browser", I would recommend using C# .Net WebBrowser, then use the runtime package XULRunner (https://developer.mozilla.org/en-US/docs/Mozilla/Projects/XULRunner).
Despite all this, I would not recommend doing anything that may be against laws of your current location, or doing anything to displease the site owner.

JSONP cross-domain call for html giving javascript errors

I'm making a JSONP cross-domain call through a developed API that enters html into a div. That attempt is causing key-word javascript errors (missing ; before statement, class is a reserved identifier, etc) and I really don't know where to start with this. The page can be accessed here: http://www.gounitedrealty.com/example.html
and the code can be viewed through an "Inspect Element". I really don't know where/how to start with resolving this, and am hoping someone who has had a similar project can lend a hand
or provide a suggestion.
Thanks very much
www.emenu.com/api/index.php?r=api/menu&host=www.gounitedrealty.com&callback=jQuery16406947022259701043_1317694125388&_=1317694126263:1
is missing the most important part of JSONP, the JSON. It's HTML.
That's because it's invalid json. It's HTML.

a strange $.get()

I have this code, a simple jQuery GET:
$.get(url, params, function(){
function_call()
})
I wonder why the function_call() is never executed. The server at url is up and running and changing the function to $.ajax() shows no errors (the error option is not executed), but it's not working.
Any clue? params is a simple JS object of two fields, and of course I've used $.get() thousands of times with no problems.
Based on the information you've given (and the documentation), it should be working. Are you absolutely sure you're actually calling it (the $.get)? Can you create a minimal, self-contained example of the problem? (That does two things: 1. It usually helps you solve the problem yourself, because you figure it out in the process; 2. It gives us more to work with. :-) )
Alternately, anomareh mentioned (in a comment) the Same Origin Policy, which you might be running into.
Your syntax looks good. When something like this doesn't work for me, it's because I have a silly mistake at some other point, like a syntax error in the callback function or formulating the URL etc.
We would need to see a little more of your process to help more. Try making you're callback function only do a simple alert. Have an alert right before the $.get() is called, ideally spouting the URL. If you control the server functionality, put a breakpoint there (or whatever you need to do) to make sure the call is getting there. Switch back to $.ajax() and see if you get the error callback function called if you switch the URL to something bogus.
I guess I make so many dumb mistakes with my javascript/jquery, that I'm good with debugging ideas. :)
Have you tried a semicolon after function_call()?
The only other thing I would try is $.get(url, params, function_call) --- this will work only if your function call has no params -- take note that function_call intentionally does not have () after it.

inspect javascript calls for gmail's buttons

i'm working on a greasemonkey script for gmail in which it'd be very useful to know what function call is made when the "send" button is clicked. (i was unable to find this using firebug, but am relatively new to javascript debugging.) it seems that one should be able to detect this, i just don't know what tool(s) to use.
thanks very much for any help.
p.s. ultimately the goal here is to be able to extract a unique message i.d. for outgoing gmail messages, which i figured would be present in this javascript call -- so if there's an alternate way to do this, that would work just as well.
Gmail's Javascript code is obfuscated to avoid this type of inspection (and also to reduce code size). It is very unlikely you'll be able to make heads or tails of it even if you manage to get Firebug to breakpoint in the code properly.
I don't think that the message id would be in the message created (in fact all the headers would be absent). My guess is that they are entered on the server side by Google before dispatching the message.
All objects in JavaScript has got a toString() method. If you can find the button then you can find it's associated events. You can then toString() those events in the FireBug console--but as levik wrote; all of the code if obfuscated, so you might just end up toString()'ing gibberish.
Here's a little pseudo-code to get you started:
document.getElementById("...").onclick.toString()
Update
It seems like it's not possible to access events added with attachEvent() and addEventListener() if you have no control over the code you want to debug.
As a sidenote, one would assume that the unique id gets assigned in the server, not in the javascript...

Categories