I am implementing something like this:
There is a JSON-based web service on a remote server. Its method can be called by simply putting specially structured URLs like this:
http://root-url/ws/service-name?request={json-string}
The {json-string}
portion contains parameters to call the method, and the response will be displayed in the browser.
And what I am trying to do is:
Implement a form on a html page, and when the user fills in the information and submits it, the response will be shown like an embedded page below the form. I tried using the <object>
tag and it reports error: failed to parse json request. Is there anyway I can do this with jQuery/javascript?
Thanks in advance.
Edit: Basic structure of my page:
<form>
...
</form>
<div id="responseContainer">
</div>
I have jQuery Code that generates a valid URL (stored in a javascript variable) string with the data from the form as parameters in it. What I want to do is to load the response page in the current html page (inside "responseContainer") with the URL.
I have tried the following methods: $.ajax():
jQuery.ajax({
url: link //where the url is stored
}).done(function( data ) {
if ( console && console.log ) {
console.log( "Sample of data:", data.slice( 0, 100 ) );
}
jQuery('#responseContainer').html(data);
});
And $.get():
$.get(link, function(data) {
$('#responseContainer').html(data);
});
But neither worked, both reported the same error in the console:
"XMLHttpRequest cannot load: ... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access."