JSONP cross-domain call for html giving javascript errors - javascript

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.

Related

How do I solve the ReferenceError in my API calls from my UI?

I have done a microsoft tutorial called Web API with Javascript
I now have a UI made with Javascript and HTML which looks like this:
How do I use the UI? I keep getting a Reference Error. Is there a specific syntax I am supposed to follow when I add and edit something via APIs?
In the future, please copy and paste error messages into your question. I would normally copy and paste the error message in my answer, but I don't want to type it all out :)
The errors (red) mean that you're trying to use JavaScript that is not defined yet. The warnings (yellow) are the reason why.
The second warning says that it could not load the JavaScript. That explains the errors. The first warning might be the reason why. It's saying that the MIME type is empty, when it should be application/javascript.
But you said in the comments that the site.js file is empty when you try to access it directly. Did you save all the JavaScript in step 4 of that tutorial to site.js?
And what are you using as a web server? IIS Express?

Converting text to javascript and executing it

I have got formatted text(which is a piece of code) in my textarea which is beautified using the codemirror.
Now when I press the button under the textaera,I need to pass a response as a variable to the above code and execute it as javascript and obtain the result.
basically I just want something similar to jsfiddle.
How can I do this using javascript/jquery?. Is there any plugins that I could use for the same?
I think you are looking for eval function in JavaScript. I do not understand what exactly you need to achieve, but this might help:
http://www.w3schools.com/jsref/jsref_eval.asp
However, as I understand you should try to avoid eval in the code, but if this is the only way, let it be.
You can run the code in an iframe on a different domain with eval function, this causes the browser to not allow the code in the iframe access to the parent page due to the Same Origin Policy.
Well known tools created to run third-party code is Google Caja and ADsafe.

Export Flash parameters to JavaScript

I'm trying to pass parameters from Flash (as 3.0) to JavaScript.
Tried all methods I found in via. Google, as:
ExternalInterface.addCallback ("fonts", recieveFromJS);
Always one and the same problem; when I try to call the fonts () swfobject, JavaScript gives the error that the method doesn't exist.
Assuming your javascript code does not have a syntax error somewhere, this usually happens because of jquery (or some other js bundle) is stepping on your code. Try using a test page with just the javascript you need, removing all other code and header entries. If it works, then add scripts and links back, one at a time, and you will find which code is breaking it. If it does not work even in your test page, then you have a code/syntax/logic problem with the snippet of code you are working with. If you still have a problem with a code snippet, post it here and I or someone will surely help debug it for you.

Programatically retrieve count of javascript errors on page

I'd like to write a test case (using Selenium, but not the point of this question) to validate that my web application has no script errors\warnings or unhanded exceptions at certain points in time (like after initializing a major library).
This information can easily be seen in the debug consoles of most browsers. Is it possible to execute a javascript statement to get this information programatically?
It's okay if it's different for each browser, I can deal with that.
not so far read about your issue (as far as I understood your problem) here
The idea be the following:
I found, however, that I was often getting JavaScript errors when the page first loaded (because I was working on the JS and was introducing errors), so I was looking for a quick way to add an assert to my test to check whether any JS errors occurred. After some Googling I came to the conclusion that there is nothing built into Selenium to support this, but there are a number of hacks that can be used to accomplish it. I'm going to describe one of them here. Let me state again, for the record, that this is pretty hacky. I'd love to hear from others who may have better solutions.
I simply add a script to my page that will catch any JS errors by intercepting the window.onerror event:
<script type="text/javascript">
window.onerror=function(msg){
$("body").attr("JSError",msg);
}
</script>
This will cause an attribute called JSError with a value corresponding to the JavaScript error message to be added to the body tag of my document if a JavaScript error occurs. Note that I'm using jQuery to do this, so this specific example won't work if jQuery fails to load. Then, in my Selenium test, I just use the command assertElementNotPresent with a target of //body[#JSError]. Now, if any JavaScript errors occur on the page my test will fail and I'll know I have to address them first. If, for some strange reason, I want to check for a particular JavaScript error, I could use the assertElementPresent command with a target of //body[#JSError='the error message'].
Hope this fresh idea helps you :)
try {
//code
} catch(exception) {
//send ajax request: exception.message, exception.stack, etc.
}
More info - MDN Documentation

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.

Categories