logo
Tags down

shadow

Ajax - XMLHttpRequest or/vs jQuery ? Is code in my question acctually the same?


By : user2176573
Date : October 14 2020, 02:15 PM
This might help you Q1: $.ajax is the generic method from Jquery to do ajax request, you even have shorter methods like $.get, $.getScript, $.getJSON, $.post, etc. But basically, both, jquery's ajax method and an XMLHttpRequest, do ajax (asyncrhonous) requests. Your examples are not the same since they do different things and the $.ajax example is generic, but in esscense, yes, they do the same.
Q2: It really depends on the developer, most of the time we use some kind of lib that helps to do ajax requests with a friendlier syntax (I use rails so I use rails-ujs for example). The thing with jquery is that you need to add jquery, if you already use it then there's no reason not to use it's methods. On the other hand, if you don't use jquery then there's no point on adding the whole framework just for the ajax methods (you can add lighter libs if you want something similar). Most people don't use the vanilla method because it's really common to use some framework that already adds custom methods to do that and also handle crossbrowser compatibility. If you want to use the vanilla methods there's always the docs https://developer.mozilla.org/es/docs/Web/API/XMLHttpRequest (o search examples of xmlhttprequest and you'll find plenty)
code :


Share : facebook icon twitter icon

AJAX: advantages to using jQuery's .ajax() instead of XMLHttpRequest?


By : stacker
Date : March 29 2020, 07:55 AM
Hope this helps You may want to give a look to jQuery's src/ajax.js source code. One reason it's 720 sloc, and not just 10 is mainly to:

is $.ajax() jQuery's way of shortening the normal code: function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest)


By : peeli
Date : March 29 2020, 07:55 AM
I hope this helps you . It's not exactly the same, but yes it's basically serving the same purpose. (there are significant differences between the functionality of the two examples though, not least of which is that one is sending a POST request and the other a GET request)
I would suggest taking a look at the (uncompressed) source code for jQuery to see what the $.ajax() function does. It is quite a lot more complex than your raw XMLHttpRequest code, but yes it does do basically the same job, and at the core of it, it does call the same XMLHttpRequest class.

Ajax php inserts some weird jquery code instead of question mark in mysql


By : Matt Ruetz
Date : March 29 2020, 07:55 AM
will help you This is because question marks are a reserved character (along with ampersands (&) and equals(=) and a few other characters they have a special meaning) - you need to use encodeURIComponent - like so:
code :
$('#send-message').submit( function(){
        var message = $('#send-message input[name=message]').val();

        if( $.trim( message ) == '' ){
        $('#send-message input[name=message]').focus();
        }
        var anon="<?php echo $anon; ?>";
        $.ajax({
            url: 'submit.php',
            type: 'POST',
            data: 'message=' + encodeURIComponent(message) + '&anon=' + encodeURIComponent(anon),
            dataType: 'json',
            success: function( payload ){
                if( payload.status == 'error' ){
                    alert('Error!');
                } else if( payload.status == 'empty-message' ){
                        $('#send-message input[name=message]').focus();
                } else if( payload.status == 'success' ){

                    $('#send-message input[name=message]').val('');
                }
            }
        });
        return false;
    });

jQuery AJAX vs. XMLHttpRequest


By : cyoborg
Date : March 29 2020, 07:55 AM
I wish this helpful for you Something else to think about, in addition to the dataType:
Since it's returning a 403 error, have you added the 'saveMetas' method in the $this->Auth->allow() method in the beforeFilter() of 'MetasController' of your CakePHP project?
code :
class MetasController extends AppController {
    public function beforeFilter() {
      parent::beforeFilter();
      $this->Auth->allow('saveMetas');
    }
    ...
    ...
}

Jquery ajax vs XMLHttpRequest


By : DisplayName=
Date : March 29 2020, 07:55 AM
may help you . Access-Control-Allow-Origin is a response header so it shouldn't be on the list of request headers: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#The_HTTP_response_headers
Remove the following:
code :
beforeSend: function (xhr) {
    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
}
headers: {
    'Access-Control-Allow-Origin': '*'
}
Related Posts Related Posts :
  • *NgFor toggle show/hide individual element
  • Add placeholder to multiple google chart string filters
  • Get value from radio button Angular Material Dialog
  • Use mergeWith of Lodash with nested objects
  • with javascript function created select onchange with counter parameter
  • SyntaxError using spread operator in webpack.config.js
  • Express - push to testing array on post request
  • Why should I use Interfaces in Typescript
  • What is a best way of detecting change of array?
  • Images are not getting the Div height when loading in jQuery
  • Find element by HTML in Cypress
  • Travsering table and storing values as key/value pair
  • Angular Material Checkbox doesn´t change state of checked
  • copy props from obj to obj in a functional Programming way
  • Bubble chart with NextJS and highcharts-react-official
  • Update value in table from Dialog Angular MAterial
  • ReferenceError because the variable is not being passed on
  • RequiredJS failed to Load a JS file
  • How can I disable the Stripe payment request button until a form is complete?
  • How to show a element immediately, such as a loading indicator, with Vue? nextTick isn't working as I expect
  • v-on:click with target not in the correct element?
  • Get last occurrence of item in array of arrays (Javascript)
  • Event binding with $(window) on dynamically created AJAX elements
  • How to use a variable in a custom function in Twilio Studio?
  • Prevent textarea from automatically scrolling when I change cursor position
  • Headless browser in Azure functions JavaScript?
  • Javascript to "fix" all hrefs of class with regex
  • How do I pass a value to list-item
  • Using component in entry component?
  • Working with different timezones in Javascript
  • Does MobX Observables have anything to do with RxJS ones?
  • Google extension how to inject my script to active tab and link with pop-up button?
  • Removing duplicate keys from object array
  • One @click event with multiple toggles
  • How to add TextToSpeech.talk("hi') action to a button
  • Not able to render vanilla webcomponent imported as template
  • How can I remove Materialize's select dropdown when using select2?
  • react-loadable multiple resource loading not working
  • Making SharePoint Lookup field multi selection in code with PNP/SP
  • input equal to a string for one array, and get string from same position from another array - JavaScript
  • Proper Method for Storing JavaScript Instances in Nan::ObjectWrap C++ Class
  • jQuery Calculate remaining characters length for input
  • Highcharts transform JSON into data without losing informations
  • How can I validate my file input name using regex?
  • Moment js interval for a day in 12 hours format
  • What would be the implementation of the function in this scenario
  • How to get text next a input tag using document.querySelector?
  • What could be reason of the error 'Maximum call stack size exceeded' inside Ember Data?
  • Leaflet polyline precision loss on zoom out
  • Convert Javascript regex to Typescript regex
  • Textext.js - Remove all tags and clean textarea
  • Array splice with unexpected results
  • Having trouble with multiple active states in ReactJS
  • Error 500 for some Ajax requests on server
  • Event call at the end of HTTP call
  • wooommerce add to cart based on gravity form radio button
  • Angular 6: table with *ngIF generates one <td> more than i need
  • how to load an external script with react?
  • Getting current stored value from database in a form on Cascading dropdowns in edit mode C# MVC
  • Best Way to Pass Query Parameters to URL Using Axios in Vue?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org