开发者

How to call JQuery Ajax Post with querystring URL

I have a web page which is redirected from a another page and have a querystring in it. now this page is calling a J开发者_Python百科query AJAX call to do some other task.

Page URL is like : http://localhost:1041/Inventory/Inventorydetail.aspx?invoiceid=3

now this page is calling a AJAX post to delete a record from the grid.

           $(".DeleteInvoiceLine").click(function() {
             //Get the Id of the record
             var record_id = $(this).attr("id");
             var loc = window.location;
             // Ask user's confirmation
             if (confirm("Do you want to delete this record?")) {
                 $.ajax({
                     type: "POST",
                     url: loc + "/DeleteInvoiceLineEntry",
                     //Pass the selected record id
                     data: "{'args': '" + record_id + "'}",
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: function(msgstr) {
                      var msg = $("#ctl00_ContentPlaceHolder1_success");
                      msg.html(msgstr.d);
                      msg.show();

                     }
                 });
             }
             return false;
         });

so when I call the AJAX call the page_Load event is called instead of the webmethod "DeleteInvoiceLineEntry".

if I have my page without the querystring passed it works fine.

could you please suggest me how I can call a AJAX call on the page which has a querystring data init.

I tried it both way passing the static URL Not working url: "Inventorydetail.aspx?invoiceid=3/DeleteInvoiceLineEntry"

Working (if there is no querystring data in the page)

url: "Inventorydetail.aspx/DeleteInvoiceLineEntry"

Thanks for your quick help.


Don't attach query string when you call ajax. It will confuse the communication as ajax actually use query string to pass json data. If you want to pass invoiceid to the ajax, include it in json data.


Change

var loc = window.location;

To

var loc = window.location.href.replace(window.location.search, '');

as Taesung Shin mentioned. The query string in the URL is confusing your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜