I am using jqgrid to retrieve data from api controller post method. I have set the jquery url,datatype and mtype like below.
url: ..api/ControllerName,
datatype: "json",
mtype: 'POST',
Problem 1: But it is not hitting the controller.
Problem 2: I also want to sent some validation data with this url to preform some validation then allow data retrieval to user.
I would recommend you to use Developer Tools of Chrome/Internet Explorer/Firefox (see Network part) or the tool like Fiddler available for free to trace HTTP traffic and to verify whether the POST request will be do sent to the server.
Depend on what API controller you use it can be that the method will be not called by the framework because not all input parameters can be initialized by the request. Typically the framework used by API controller on the lower level will return an error back to jgGrid. You can see the response in the HTTP traffic. I recommend you to use loadError callback of jqGrid to display an error message in such case. See the answer for more details.
To send additional parameters to the server you can use postData parameter of jqGrid. I recommend you to read the answer for more details.
By the way some standard parameters will be sent by jqGrid to the server. You can use prmNames option of jqGrid to rename the standard parameters or to remove some from there (by usage null as the value of the corresponding prmNames property).
I found some help jqGrid With ASP.NET Web API
Related
Can anyone help me in how to get the url, from the Ajax response in Ember.
This is to handle a specific use case in which server redirects to another url and returns data from the new url(302 redirect).
If i am able to get the url form the response, then i can check if the requested url is different from the response url and can take the action accordingly.
Note: If we use Angular (tried with Angular4), then we can get the response details including url and header from the response, if you use Http service from '#angular/http'
I am using following config for EmberJS
-ember-cli: 2.14.2
-node: 8.1.0
-os: darwin x64
In comment you specified that you fetch the record using Ember.$.ajax. Ember.$ is not more than an alias for jQuery. So Ember.$.ajax is the same as jQuery.ajax. Following jQuery.ajax documentation success function is called with jqXHR object as third argument. This is a superset of browsers native XMLHttpRequest object. XMLHttpRequest object provides a read-only property responseURL which is what you are looking for.
In general I would recommend to not use jQuery.ajax in modern ember application. There are two great alternatives:
ember-fetch provides a HTML5 fetch polyfill from github wrapped and bundled for ember-cli.
ember-ajax provides a service for making AJAX requests which provides RSVP promises.
There is also work ongoing to migrate away from jQuery.ajax in ember-data.
To keep it simple I have a feedback form on my website. Whether or not the following is best practice is moot as I'm interested in the way this works. The customer can fill out their name, email address and reason for feedback on the form. This is then posted via AJAX to a server side function called SendFeedback. I am using .NET MVC4 and the SendFeedback method simply returns a true or false string. However I was testing out sending scripts through it to check out the security of the form and noticed that when I attempted to send through HTML tags or javascript that the SendFeedback method wasn't being invoked at all and instead my custom error page was being sent back to the client side AJAX response (if I sent though standard text, the SendFeedback method was being invoked as expected). Where is the first place that AJAX data is sent before it is passed into the server side method I am calling from the client? Is there any way to set a breakpoint here so I can examine what is going on?
This is part of an ASP.NET feature called request validaiton which is turned on by default. And which executes in ASP.NET handler before your code. If you desire, this feature can be turned off in web.config, but I would strongly advise against it.
More information on request validation can be found in MSDN.
Firstly, I have to admit I am new to Magento and PHP. I am writing the configuration for my custom module. I would like to allow entry of some information, then send that information to a servlet on my web server where it is processed and a response returned and displayed in the configuration gui in a read-only field.
I am getting my guidance from various web articles and by looking at other modules' code. A module that does something similar is the PayPal module. However, it brings up a new browser window where the user logs in and enters their details. I just want to send the data gathered and wait for the response.
In my system.xml file I specify a frontend_model. In that frontend_model, the _prepareLayout method sets the template to my template, and in that template I have an HTML button. I added an onClick event handler to that button which makes an AJAX call to my web site. Unsurprisingly (because of the same origin policy I assume) the AJAX call fails with a code of 0.
I guess what I should be doing is when the user clicks the button, the request including the data they have entered in the other fields, is sent to the Magento server, and the AJAX call to my web site is made from there? Or perhaps my approach is completely wrong and there is a more appropriate way to achieve this?
Thank you.
You're right about the same origin policy. The best approach here would be to have the button trigger an ajax call to a local magento based controller, which itself uses curl or some other http request library to forward on a request to your remote servlet and process the feedback.
Try searching here "JSONP" or google the same thing. Dependent of javascript library you are using there are pre-made components/plugins to achieve what you are after.
I want to use mootools and SqueezBox class to handle a request to a RESTful service. I don't want to use any server-side script. I am using AJAX. I send a request to the following url using GET method.
http://www.idevcenter.com/api/v1/links/links-upcoming.json
but I receive a 404 error. Is it because cross-site scripting? here is my code:
SqueezeBox.initialize({handler:'url',ajaxOptions:{method:'GET'}});
$('a.modal').addEvent('click',function(e){
new Event(e).stop();
SqueezeBox.fromElement($('a.modal'));
});
In Firebug console, sometimes 'aborted' is shown and sometimes '404'.what is wrong with that?
XMLHttpRequest is subject to the Same Origin Policy; if the document your JavaScript is running within is not from the same origin as the service you're trying to call, the call will be disallowed for security reasons.
There is now a proposed standard for cross-origin resource sharing to address this. It may be that the service you're trying to use supports it; if so, using a browser that implements CORS (recent versions of Firefox and Chrome do, as do some others) may work. IE8 supports it but requires that you do extra work.
You cannot use XMLHttpRequest (that is, ordinary "ajax") to call a service on a server that is not in your domain.
You can, however, use the JSONP trick, which takes advantage of the fact that the browser will load Javascript from other domains. However, the service has to know that you're going to do that, and it has to understand the protocol. That particular service seems perfectly willing to give me a JSON response, but it doesn't pay attention when I give it a "callback" parameter. (I've tried both "callback" and "jsonp" and the JSON blob that comes back is the same, without a function call wrapper.)
I have an issue where I executing an AJAX request. Instead of seeing the normal POST or GET preceeding the action page url, I see OPTIONS. The data is successfully posted, but there is no response from the action page. What does OPTIONS indicate?
"The OPTIONS method represents a
request for information about the
communication options available on the
request/response chain identified by
the Request-URI. This method allows
the client to determine the options
and/or requirements associated with a
resource, or the capabilities of a
server, without implying a resource
action or initiating a resource
retrieval."
source
This is due to a cross-domain AJAX attempt. Sometimes something as harmless-looking as requesting h ttp://www.example.com from h ttp://example.com can cause unexpected behavior.