简体   繁体   中英

AJAX query: load the page, before success

I am currently trying to make a post request using AJAX:

 $.ajax({ url: 'http://....', type: 'post', data: {test:'val', studentAnswer:'val'}, success: function(data, status, jq_xhr) { console.log(data); } }); 

However, the page I'm trying to get is an HTML page that has to load JavaScript. The problem is that I can not load the page, and I want only to get the response, not the entire source code of the page.

Do you have a solution ?

Thank you!

Please make sure the URL you're reaching out to is set up to take POST requests.

Can you share the URL you are hitting?

If you also manage the server - create a method to handle POST requests not to return an HTML file. If the endpoint you are reaching out to is a webpage, it will always return the source HTML file.

Here's an example:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://requestbin.fullcontact.com/qq3wmoqq",
  "method": "POST",
  "headers": {
    "cache-control": "no-cache"
  },
  "data": "{test:'val', studentAnswer:'val'}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

To check the actual request going through: https://requestbin.fullcontact.com/qq3wmoqq?inspect

try put your code in document ready

$( document ).ready(function() {
...here your code..
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM