jQuery Ajax POST example with PHP

Basic usage of .ajax would look something like this: HTML: jQuery: Note: Since jQuery 1.8, .success(), .error() and .complete() are deprecated in favor of .done(), .fail() and .always(). Note: Remember that the above snippet has to be done after DOM ready, so you should put it inside a $(document).ready() handler (or use the $() shorthand). Tip: You can chain the callback handlers like this: $.ajax().done().fail().always(); PHP (that is, form.php): Note: Always sanitize posted data, … Read more

JSON.parse() not working

I dont think you should call JSON.parse(jsonObject) if the server is sending valid JSON as it will be parsed automatically when it retrieves the response. I believe that if You set the Content-type: application/json header it will be parsed automatically. Try using jsonObject as if it was already parsed, something like: Without calling JSON.parse before.

Execute PHP function with onclick

First, understand that you have three languages working together: PHP: It only runs by the server and responds to requests like clicking on a link (GET) or submitting a form (POST). HTML & JavaScript: It only runs in someone’s browser (excluding NodeJS). I’m assuming your file looks something like: Because PHP only responds to requests … Read more

How to solve the error “SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.” in IE

I don’t think it’s a good idea to ask your customers to disable this configuration at all. Remember that enabling and making this change does not only apply to your website but to other websites as well. There’s a huge security reason why it is disabled in Internet and Restricted Sites zones by default and … Read more

What’s the point of the X-Requested-With header?

A good reason is for security – this can prevent CSRF attacks because this header cannot be added to the AJAX request cross domain without the consent of the server via CORS. Only the following headers are allowed across origins: Accept Accept-Language Content-Language Last-Event-ID Content-Type any others cause a “pre-flight” request to be issued in CORS supported browsers. … Read more